Forum Moderators: coopster
I've never come across this before - I'm using php mail() to send just a regular text email (nothing fancy at all) but when the email comes in, NOT ONLY do I get the body of the email, but I'm also getting header information, like this:
Content-Type: multipart/mixed; boundary="5eefe8303e159f95bcab599faa89200c"
--5eefe8303e159f95bcab599faa89200c
Content-Type: multipart/alternative; boundary="5eefe8303e159f95bcab599faa89200c_htmlalt"
--5eefe8303e159f95bcab599faa89200c_htmlalt
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
**********************************************
EMAIL FROM SOME WEBSITE: CONTACT FORM
**********************************************
Name: Some Name
Email: some email
**********************************************
CONTACT MESSAGE
**********************************************
test message
**********************************************
MESSAGE SENT
**********************************************
March 3, 2008, 7:24 am
--5eefe8303e159f95bcab599faa89200c_htmlalt--
--5eefe8303e159f95bcab599faa89200c--
Has anyone else ever come across this before? I've used the same function to send emails (shown below) many times before with other clients so I don't understand why this is happening this time, and I can't find any error in my code.
PREP EMAIL DATA IS HERE:
/****************** PREPARE SENDERS EMAIL DATA ******************/
$fullName = stripslashes($fullName);
$email = stripslashes($email);
$yacht = stripslashes($yacht);
$position = stripslashes($position);
$phone = stripslashes($phone);
$fax = stripslashes($fax);
$subject = stripslashes($subject);
$message = stripslashes($message);
$message = snl2dnl($message);
$ccName = $ccAdd = FALSE;
$timeStamp = date("F j, Y, g:i a", displayLocalTime(14, 'Ahead'));
/****************** PREPARE RECEIVER'S EMAIL DATA ******************/
$toName = $dept;
switch($dept)
{
case 'General Information':
$toAdd = $_SESSION['EmailAccounts']['Information'];
break;
case 'Crewing Department':
$toAdd = $_SESSION['EmailAccounts']['Crewing'];
break;
case 'Accounting Department':
$toAdd = $_SESSION['EmailAccounts']['Accounting'];
break;
case 'Client Services':
$toAdd = $_SESSION['EmailAccounts']['Client'];
break;
case 'Crew Services':
$toAdd = $_SESSION['EmailAccounts']['Crew'];
break;
}
$fromName = $fullName;
$fromAdd = $email;
$snl = "\n";//Single new line character
$dnl = "\n\n";//Double new line characters
$body =
'**********************************************' . $snl .
'EMAIL FROM CREW ASIA WEBSITE: CONTACT FORM' . $snl .
'**********************************************' . $dnl .
'Name: ' . $fullName . $dnl .
'Position: ' . $position . $dnl .
'Yacht: ' . $yacht . $dnl .
'Phone: ' . $phone . $dnl .
'Fax: ' . $fax . $dnl .
'Email: ' . $email . $dnl .
'**********************************************' . $snl .
'CONTACT MESSAGE' . $snl .
'**********************************************' . $dnl .
$message . $dnl .
'**********************************************' . $snl .
'MESSAGE SENT' . $snl .
'**********************************************' . $dnl .
$timeStamp;
$body = wordwrap($body, 70);
$attachments = FALSE;
$emailType = 'Text';
$result = send_mail($toName, $toAdd, $fromName, $fromAdd, $ccName, $ccAdd, $subject, $body, $emailType, $attachments);
EMAIL FUNCTION IS HERE:
function send_mail($toName, $toAdd, $fromName, $fromAdd, $ccName, $ccAdd, $subject, $body, $emailType, $attachments)
{
$eol = "\r\n"; //End of line characters
$mime_boundary = md5(time());
# Common Headers
$headers = "To: " .$toName."<".$toAdd.">".$eol;
$headers .= "From: ".$fromName."<".$fromAdd.">".$eol;
if($ccName) $headers .= "Cc: " .$ccName."<".$ccAdd.">".$eol;
$headers .= "Reply-To: ".$fromName."<".$fromAdd.">".$eol;
$headers .= "Return-Path: ".$fromName."<".$fromAdd.">".$eol;
$headers .= "Message-ID: <".time()."-".$fromAdd.">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= "X-Priority: 1".$eol;
$headers .= "X-MSmail-Priority: High".$eol;
# Boundry for marking the split & Multitype Headers
$headers .= "MIME-Version: 1.0".$eol.$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol;
# Open the first part of the mail
$msg = "--".$mime_boundary.$eol;
$htmlalt_mime_boundary = $mime_boundary."_htmlalt";
# Setup for text OR html -
$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol;
if($emailType === 'Text')
{ # Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body . $eol . $eol;
}
else
{ # HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body . $eol . $eol;
}
//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol;
if($attachments)
{
$fileName = $_FILES['upload']['name'];
$fileType = $_FILES['upload']['type'];
$filePath = $_FILES['upload']['tmp_name'];
$fileHandle = fopen($filePath, 'rb');
$data=fread($fileHandle, filesize($filePath));
$data=chunk_split(base64_encode($data));
fclose($fileHandle);
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$fileType."; name=\"" . $fileName . "\"" . $eol;
$msg .= "Content-Transfer-Encoding: base64" . $eol;
$msg .= "Content-Description: " . $fileName . $eol;
$msg .= "Content-Disposition: attachment; filename=\"" . $fileName . "\"" . $eol . $eol;
$msg .= $data . $eol . $eol;
}
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;
# FORCE/ENSURE THAT $fromAdd IS USED IN THE HEADER
ini_set("sendmail_from",$fromAdd);
# SEND THE EMAIL
$mail_sent = mail($toAdd, $subject, $msg, $headers);
ini_restore("sendmail_from");
# if there are attachments to this email, then delete them after the email has been sent.
if($attachments) unlink($filePath);
return $mail_sent;
}
I can't test this locally (I've got to put it on the live server) as I'm always getting "Relaying denied. IP name possibly forged [210.14.45.000]" errors from my localhost dev environment - very irritating - which will be the grist of another thread.
Sorry this is such a long post. Appreciate any help in advance.
Neophyte