HTML and CSS Reference
In-Depth Information
ADDING A HEADER AND AUTO-REPLY IN PHP
As was hinted in the i ctitious e-mail used in the example, it would be nice to have an
automatic e-mail reply to users when they send an e-mail. Again, using the mail() function
in PHP, all you have to do is add a second mailer. Using the $name variable and $email , you
can personalize a reply. Additionally, you can add a header to the e-mail that is sent to the
user and to the Web site owner.
First, the mail() function requires a fourth parameter. Breaking down the four parameters,
you can lay out the following:
Recipient (e-mail address)
Subject (what is placed in the subject line)
Content (the body of the message)
Header (the From and Reply To addresses)
In the initial example, the From and Reply To address was concatenated to the content.
However, using the header parameter, you can let the header take care of it.
h is next listing ( mailer2.php in this chapter's folder at www.wiley.com/go/
smashinghtml5 ), shows the same program with the added header and the auto-reply.
Very little has been added, and much has been enhanced.
342
<?php
$name ;
$email ;
$comments ;
$subject ;
$eBiz =”waz@wazoo.net”;
if(isset($_POST['sender']))
{
$name =$_POST[“userName”];
$email =$_POST[“mailNow”];
$comments =$_POST[“talk”];
$subject =$_POST[“subject”];
}
$headers = “From-> $name :\r\n Send reply to: $email ”;
$reply =”Dear $name , \r\n Thank you for sending us your comments. We at Wazoo Web
Site Design and Development believe that customer care is an essential of doing
business—not an optional service.\r\n”;
$reply .= “As soon as we can review your comments, one of our associates will get
back to you.”;
$reply .=”\r\n Sincerely, Phillip Pickle,\r\n President, WWDD”;
mail ($email ,”Thank you for your thoughts”,$reply);
mail ($eBiz,$subject,$comments,$headers );
echo “Your e-mail has been sent to $eBiz . Thank you for your interest in Wazoo Web
Site Design and Development.”;
?>
 
Search WWH ::




Custom Search