Mail from a php script correctly showing in TB, not in Mail

the mail() function

Moderators: macek, egami, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 17
Joined: Sun Apr 01, 2012 11:52 pm

Mail from a php script correctly showing in TB, not in Mail

Post by fbartolom » Thu May 24, 2012 12:52 am

I have a script that sends an email upon the completion of a form entrance. The sent message is correctly shown when viewed on Thunderbird but when viewed on Mail, either on a Mac or an iPhone, it is left totally uninterpreted. You may see the email by completing the form at:
and this is the snippet of code performing the operation:

Code: Select all

if ($email=="") exit;
$to = $email;
//define the subject of the email
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time())); 
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From:\r\nReply-To:\r\nBcc:";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
//define the body of the message.
//Turn on output buffering
ob_start(); //Turn on output buffering
--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<? echo $contentPlain; ?>

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

<? echo "<a href=\"\"><img border=\"0\" src=\"\" width=\"640\" height=\"363\" alt=\"In Arrivo! for iPhone/iPad - Easier Travel by Bus in Rome\"></a><p>".
$contentHtml; ?>

--PHP-alt-<?php echo $random_hash; ?>--
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
$headers .= 'Bcc:' . "\r\n";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
What might be wrong?

Post Reply

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest