This is my script.....
[code=php]
<?php
$to = "example@exampl e.co.uk";
$subject = "subject";
//minimum characters allowed in the message box
$msg_min_chars = "10";
//maximum characters allowed in the message box
$msg_max_chars = "250";
function validate_form_i tems()
{
global $msg_min_chars, $msg_max_chars;
$msg_chars = "{".$msg_min_ch ars.",".$msg_ma x_chars."}";
$form_items = array(
"name" => array(
"regex" => "/^([a-zA-Z '-]+)$/",
"error" => "Name appears to be in inproper format",
),
"email" => array(
"regex" =>
"/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/",
"error" => "Please enter a valid email address",
),
"message" => array(
"regex" => "/^.{$msg_chars}$/",
"error" => "Your message is either too short or exceeds $msg_max_chars characters",
),
);
$errors = array();
foreach($form_i tems as $item_name => $item_props)
{
if (!preg_match($i tem_props["regex"], trim($_POST[$item_name])))
{
$errors[] = $item_props["error"];
}
}
return $errors;
}
function email($from, $to, $subject, $message)
{
$headers = "From: ".$from."\r \n";
$headers .= "Reply-To: ".$from."\r \n";
$headers .= "Return-Path: ".$from."\r \n";
if (mail($to,$subj ect,$message,$h eaders) ) {
echo "Thank you for your inquiry, Your message has been received. <br>We will get back to you as soon as we can.";
} else {
echo "Your message could not be sent at this time. Please try again.";
}
}
function print_error($er rors)
{
foreach($errors as $error)
{
echo $error."<br>";
}
}
function form_process()
{
global $to, $subject;
$errors = validate_form_i tems();
if(count($error s) == 0)
{
$errors [] = email(trim($_PO ST["email"]), $to, $subject, $_POST["message"]);
}
print_error($er rors);
}
form_process();
?>
[/code]
My form......
[code=php]
<form id="test" method="post" onsubmit="retur n false;">
<table border="0">
<tr>
<td colspan="2">
<div id="errors">
</div>
</td>
</tr>
<tr>
<td colspan="2">
<font size="+2"><b>Em ail Us</b></font>
</td>
</tr>
<tr>
<td>
<b>Name:</b>
<input type="text" name="name" id="name" size="25" maxlength="20" />
</td>
</tr>
<tr>
<td>
<b>Email:</b>
<input type="text" name="email" id="email" size="25" maxlength="35" />
</td>
</tr>
<tr>
<td>
<b> Messag e:</b>
</td>
<td>
<i>(max 250 characters allowed)</i>
</td>
</tr>
<tr>
<td colspan="2">
<textarea name="message" id="message" cols="36" rows="10"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="submit" name="submit" onclick="javasc ript: sendRequest();" />
</td>
</tr>
</table>
</form>
[/code]
please help
[code=php]
<?php
$to = "example@exampl e.co.uk";
$subject = "subject";
//minimum characters allowed in the message box
$msg_min_chars = "10";
//maximum characters allowed in the message box
$msg_max_chars = "250";
function validate_form_i tems()
{
global $msg_min_chars, $msg_max_chars;
$msg_chars = "{".$msg_min_ch ars.",".$msg_ma x_chars."}";
$form_items = array(
"name" => array(
"regex" => "/^([a-zA-Z '-]+)$/",
"error" => "Name appears to be in inproper format",
),
"email" => array(
"regex" =>
"/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/",
"error" => "Please enter a valid email address",
),
"message" => array(
"regex" => "/^.{$msg_chars}$/",
"error" => "Your message is either too short or exceeds $msg_max_chars characters",
),
);
$errors = array();
foreach($form_i tems as $item_name => $item_props)
{
if (!preg_match($i tem_props["regex"], trim($_POST[$item_name])))
{
$errors[] = $item_props["error"];
}
}
return $errors;
}
function email($from, $to, $subject, $message)
{
$headers = "From: ".$from."\r \n";
$headers .= "Reply-To: ".$from."\r \n";
$headers .= "Return-Path: ".$from."\r \n";
if (mail($to,$subj ect,$message,$h eaders) ) {
echo "Thank you for your inquiry, Your message has been received. <br>We will get back to you as soon as we can.";
} else {
echo "Your message could not be sent at this time. Please try again.";
}
}
function print_error($er rors)
{
foreach($errors as $error)
{
echo $error."<br>";
}
}
function form_process()
{
global $to, $subject;
$errors = validate_form_i tems();
if(count($error s) == 0)
{
$errors [] = email(trim($_PO ST["email"]), $to, $subject, $_POST["message"]);
}
print_error($er rors);
}
form_process();
?>
[/code]
My form......
[code=php]
<form id="test" method="post" onsubmit="retur n false;">
<table border="0">
<tr>
<td colspan="2">
<div id="errors">
</div>
</td>
</tr>
<tr>
<td colspan="2">
<font size="+2"><b>Em ail Us</b></font>
</td>
</tr>
<tr>
<td>
<b>Name:</b>
<input type="text" name="name" id="name" size="25" maxlength="20" />
</td>
</tr>
<tr>
<td>
<b>Email:</b>
<input type="text" name="email" id="email" size="25" maxlength="35" />
</td>
</tr>
<tr>
<td>
<b> Messag e:</b>
</td>
<td>
<i>(max 250 characters allowed)</i>
</td>
</tr>
<tr>
<td colspan="2">
<textarea name="message" id="message" cols="36" rows="10"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="submit" name="submit" onclick="javasc ript: sendRequest();" />
</td>
</tr>
</table>
</form>
[/code]
please help
Comment