|
Posted by Andy on 09/17/05 10:47
I need your help to check if my autoresponder will work in the following
script. I am testing my PHP scripts on free server, which dosen't allow me
to send email letters from my website.
Please tell me if every thing is ok, if not please correct my mistake. Thank
you for your help.
This is: "contact_form.php"
<?
// This is the beginning of the PHP code
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$error_msg = "";
$msg = "";
if(!$email){
$error_msg .= "Your email \n";
}
if($email){
if(!eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}", $email)){
echo "\n<br>That is not a valid email address. Please <a
href=\"javascript:history.back()\">return</a> to the previous page and try
again.\n<br>";
exit;
}
$msg .= "Email: \t $email \n";
}
if($comments){
$msg .= "Comments: \t $comments \n";
}
$sender_email="";
if(!isset($name)){
if($name == ""){
$sender_name="Web Customer";
}
}else{
$sender_name=$name;
}
if(!isset($email)){
if($email == ""){
$sender_email="Customer@website.com";
}
}else{
$sender_email=$email;
}
if($error_msg != ""){
echo "You didn't fill in these required fields:<br>"
.nl2br($error_msg) .'<br>Please <a
href="javascript:history.back()">return</a> to the previous page and try
again.';
exit;
}
$mailheaders = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailheaders .= "From: $sender_name <$sender_email>\r\n";
$mailheaders .= "Reply-To: $sender_email <$sender_email>\r\n";
mail("your@email.com","Contact Us"stripslashes($msg), $mailheaders);
header("Location: http://yahoo.com/"); /* Redirect browser */
$myname = "Your Name Here";
$mymail = "your@email.com";
$subject = "Thank you for your mail!";
$body = "Hi. This is an auto response to let you know that I've successfully
received your
email sent through my email form @ mywebsite.com. Thanks! I'll get back to
you
shortly.";
$headers = "Content-Type: text/plain; charset=us-ascii From: $myname
<$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP";
if ($email != "") { mail($email,$subject,$body,$headers); }
//This is the end of the PHP code
?>
And this is a simple "contact form" for the script.
<!-- BEGIN THE COPYING HERE!!!!!!! --><!-- beginning of the form -->
<form METHOD=POST ACTION="contact_form.php">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr><td>Name:</td><td> <INPUT TYPE="text" NAME="name"></td></tr>
<tr><td>E-mail:</td><td> <INPUT TYPE="text" NAME="email"></td></tr>
<tr><td valign="top">Comments:</td><td><TEXTAREA NAME="comments" ROWS="10"
COLS="34"></TEXTAREA></td></tr>
<td><br><input type="submit" name="Submit" value="Submit"></td>
<td><br>
<input type="reset" name="reset" value="Reset"></td></tr></table>
</form>
<!--end of the form -->
<!-- END THE COPYING HERE!!!!!!! -->
[Back to original message]
|