Tango Hosting Support
How to Setup a Basic PHP Email Form on Windows 2003 server
*** Tango Hosting offers the following support file as a courtesy.
If you need further assistance with configuration please contact support@tangohosting.com
for a price quote. ***
Below is a simple cut and paste solution for a Basic PHP E-mail form with form validation that will e-mail you from your web site. After submission it will confirm that the email has been sent.
Create a PHP file called mail.php or whatever you like (make sure the file extension is .php e.g. anything.php). Cut and paste the code below in the PHP file. This file contains the form and PHP code that validates and emails the form.
(customize the parts in bold to reflect your own information):
<!-- Cut code below this line -->
<?php
// Change below to the email address where you want to receive the message.
//
(inside the quote marks 'receive@yourdomain.com'')
$myemail = 'receive@yourdomain.com';
// Change this to the subject of your message.
//
(inside the quote marks 'PHP Mail Form Subject'')
$subject = 'PHP Mail Form Subject';
$op = $_POST[op];
if($op == 'contact')
{
$name = stripslashes($_POST[name]);
$email = stripslashes($_POST[email]);
$text = stripslashes($_POST[text]);
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email))
{
$status = "We're sorry, but you've entered an incorrect email address.<br>";
}
if(!$name)
{
$status .= "Please enter your name.<br>";
}
if(!$text)
{
$status .= "Please enter a message.<br>";
}
if(!$status)
{
$header = "From: $email\r\nReply-To: $email\r\n";
$message = "
Name: $name
Email: $email
Message: $text
";
if(mail($myemail, $subject, $message, $header))
{
$status = "Thank you for your Feedback!!<br><br>";
}
else
{
$status = "There was a problem sending your feedback, please try again later.<br><br>";
}
}
else
{
$status .= "<br>Please press <u>back</u> on your browser to resubmit.<br><br>";
}
}
// Now check the referer page and ensure it's a proper URL
$referer = $_SERVER[HTTP_REFERER];
if(!preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $referer))
{
unset($referer);
}
?>
<?php print $status; ?>
<form method="post" action="<?php print $_SELF; ?>">
<input type="hidden" name="op" value="contact">
Name:<br>
<input name="name" size="35" value=""><br>
E-mail address:<br>
<input name="email" size="35" value=""><br>
<br>
Message:<br>
<textarea name="text" cols="50" rows="10"></textarea><br><br>
<input type="submit" value="Send message!">
<!-- Cut code above this line -->
That's it!
Tango Hosting Support Team |