
Here's the code.
Code: Select all
// Prep and send the email.
// Message body assembly.
$body = "Nana,\n\n";
$body .= "<p>An email has been sent from ".$form['title']." ".$form['firstname']." ".$form['lastname'].". Here is the message:</p>\n";
$body .= "<pre>".$form['comment']."</pre>\n\n";
$body .= "<p>This additional information was provided:<br />\n\n";
$body .= $form['title']." ".$form['firstname']." ".$form['lastname']."<br />\n";
$body .= $form['addr1']."<br />\n";
if(isset($form['addr2']) && ($form['addr2'] != ''))
$body .= $form['addr2']."<br />\n";
$body .= $form['city'].", ".$form['state']." ".$form['zip']."<br /><br />\n\nPhone: ".$form['phone']."<br />\n";
if(isset($form['fax']) && ($form['fax'] != ''))
$body .= "Fax: ".$form['fax']."<br /><br />\n\n";
$body .= 'Email: <a href="mailto:'.$form['email'].'">'.$form['email']."</a></p>\n\n";
$body .= '<p>Submitting IP: <a href="http://ws.arin.net/whois/?queryinput='.$form['ip'].'" target="_blank">'.$form['ip']."</a></p>\n";
// Make sure we have a subject which shows the Date/Time submitted.
$timestamp = date("M. jS, Y @ g:i a");
$subject = "$site contact form submitted on $timestamp";
### Generate message headers.
$mail_header = "From: ".$form['firstname']." ".$form['lastname']." <".$form['email'].">\r\n".
"Reply-To: ".$form['firstname']." ".$form['lastname']." <".$form['email'].">\r\n".
"MIME-Version: 1.0\r\n";
$boundary = uniqid("HTMLEMAIL");
// Attach Plain Text Version
$mail_header .= "Content-type: multipart/alternative; boundary=$boundary\r\n\r\n".
"This is a multi-part message in MIME format.\r\n\r\n".
"--$boundary\r\n".
"Content-type: text/plain; charset=iso-8859-1\r\n".
"Content-transfer-encoding: base64\r\n\r\n";
$mail_header .= chunk_split(base64_encode(strip_tags($body)));
// Attach HTML version
$mail_header .= "--$boundary\r\n";
$mail_header .= "Content-type: text/html; charset=iso-8859-1\r\n".
"Content-transfer-encoding: base64\r\n\r\n";
$mail_header .= chunk_split(base64_encode($body));
// Sendmail -f option
$param = "-f ".$form['email'];
// AWAY WE GO!
if(!mail($to,$subject,$body,$mail_header,$param)){
echo "<h1>Error sending message.</h1>";
exit;
}