[Nov.17.2008]
 
                                  Email us
Zenguy's Email Script
 
contact.php
<table border="0" align="center" cellpadding="0" cellspacing="0">
  <form action="contact2.php" method="POST">
  <tr>
    <td><input type="text" name="email" style="display: none;" value="bots are bad "></td>
  </tr>   <tr>
    <td width="141" align="right">Your name: </td>
    <td colspan="2"><input type="text" name="tt765tt" size="20" value=""/>*</td>
  </tr>
  <tr>
    <td align="right">Your email: </td>
    <td colspan="2"><input type="text" name="oo456oo" size="20" value=""/>*</td>
  </tr>
  <tr>
    <td align="right" >Subject: </td>
    <td colspan="2"><input type="text" name="ww908ww" size="20" value=""/>*</td>
  </tr>
  <tr>
    <td align="right">Comments: </td>
    <td width="199"><textarea name="mm657mm" rows="8" cols="30" value=""></textarea></td>
    <td width="140">*</td>
  </tr>
  <tr>
    <td colspan="2"> <input type="submit" name="submit" value="Send Email" /></td>
  </tr>
  </form>
</table>
 
contact2.php  

<?PHP

// 1st check
if (!$_POST['email'] == "bots are bad")
{
// If the hidden field "email" has been changed from bots are bad...it's a bot,
// (Remember our 1st trick from the contact.php?)
// terminate execution of the script.
exit();
}else{
// The field was not changed, on with the next check.
}

// 2nd check
include 'contact3.php';
// This is the function to validate the email.
// The code is displayed further in the tutorial.
// We need to include the page that will validate the posted email.
// Also use the trim() function to clean up any spaces from each end.
$email = trim($_POST['oo456oo'])
if(!validateEmail($email))
{
// If the email is not a valid one, send an error message.
echo "<center><p>&nbsp;</p>";
echo "Not a valid email address.<br />";
echo "<a href=\"contact.php\" title=\"Back\">Back</a></center>";
// terminate execution of the script.
exit();
}else{
// The email looks good, on with the next check.
}

// 3rd check
if (!$_POST['submit'])
{
// User has come to this page wrongfully, they did not post from contact.php.
echo "<center><p>Error!</p>";
//************** Edit below if need be**************//
echo "<a href=\"index.php\" title=\"Back\">Back</a></center>";
// terminate execution of the script.
exit();
}else{
// The user is here correctly, let set some variables from the form.
}

// Set your users info from the previous form.
$name = $_POST['tt765tt'];
$email = $_POST['oo456oo'];
$subject = $_POST['ww908ww'];
$comments = $_POST['mm657mm'];

// 4th check
if ($name == "" OR $email == ""OR $subject == "" OR $comments == "")
{
// If certain fields are empty send an error message.
echo "<center><p>You forgot a mandatory field.</p><br>";
echo "<a href=\"contact.php\" title=\"Back\">Back</a></center>";
// terminate execution of the script.
exit();
}else{
// All fields have some text
}

//Change YOUR_EMAIL_HERE@YOUR_EMAIL.com to your email.
$my_email = "YOUR_EMAIL_HERE@YOUR_EMAIL.com";

// Set date and time
$today = date("m.d.Y");
$time = date("H:i:s");

// Make a nice looking layout for the email
$message =
"Message sent: $today at $time:\n\n".
"From: $name\n".
"Email: $email\n".
"About: $subject\n\n".
"--------------------------- COMMENTS ---------------------------\n\n".
$comments.
"\n\n--------------------------------------------------------------------------\n\n";

// Send the email
mail($my_email, $subject, $message, "From: $name <$email>");
?>
<!-- Everything worked!! -->
<table align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center">Thank you for your inquiry, your email has been sent.</td>
  </tr>
</table>

 
contact3.php  
<?PHP
function validateEmail ( $email )
{
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";// Presume that the email is invalid
$valid = 0;// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("@",$email);
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}return $valid;}
?>
Zentyx.com © 2005 - 2008