Step 1: copy this code and save it as mail.php and change the text like youremail@youremail.com to your actually email address etc.
Create two extra static HTML pages:
successForm.html - just a simple page saying Email was successfully sent
failureForm.html - just a simple page saying Email was unsuccessfully sent
PHP Code:
<?php echo "<HTML><p>Please wait while we send your email...</p> <head>"; $to = 'youremail@youremail.com'; if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;} while(list($key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;} $SpamErrorMessage ="No Websites URLs permitted"; if (preg_match("/http/i","$Firstname")) {echo "$SpamErrorMessage"; exit ();} if (preg_match("/http/i","$Surname")) {echo "$SpamErrorMessage"; exit ();} if (preg_match("/http/i","$Email")) {echo "$SpamErrorMessage"; exit ();} $message = stripslashes($message); $subject = "Website Enquiry"; $headers = "From: You". $_POST['email'] . "\n"; $success = mail($to,$subject,$message,$headers); if ($success){echo '<meta http-equiv="refresh" content="1;URL=successForm.html">';} else{echo '<meta http-equiv="refresh" content="1;URL=failureForm.html">';} echo '</head><body></body></html>'; ?>
-------------------------
Step 2: In your contact page set the form action to the root file of the mail.php so if it in a file called contactus then it would be '../contactus/mail.php' etc... and set the action to post.
That's it. Hope this helps...
|