Trying to send a MIME e-mail in both plain text and html (per client request). If I just send with Content-Type: text/html, it will definitely show in e-mail viewer. The problem is when I try to do the multipart/alternative content-type, I get a blank e-mail in Hotmail and Yahoo. Code below. Any help would be greatly appreciated.

// E-mail Body Message
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

$message = "Content-Transfer-Encoding: 7bit\n" . "This is a multi-part message in MIME format. This part of the E-mail should never be seen. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.\n\n" . "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=iso-8859-1\n" . "Content-Transfer-Encoding: 7bit\n\n" .
"This is the text portion of an HTML e-mail.\n" . "--{$mime_boundary}\n" .
"Content-Type: text/html; charset=iso-8859-1\n" . "Content-Transfer-Encoding: 7bit\n\n" .
"<html><body><p>Sent By: ". $name . "<br /><br />" . "Sender's E-mail Address: ". $sentby . "<br /><br />" . "Personal Message: " . $comment . "<br /><br />" . "URL: <a href='" . $url . "'>" . $url . "</a></p>" . $PHPrint . "</body></html>" . "--{$mime_boundary}--";

$headers = "From: " . $from . "\n";
$headers.= "Reply-To: " . $sentby . "\n";
$headers.= "MIME-Version: 1.0\n" . "Content-Type: multipart/alternative;\n" . " boundary=\"{$mime_boundary}\n\"";

mail($email, $subject, $message, $headers);
echo "<h1>The WorkKeys<sup>&reg;</sup> Charts were successfully submitted.</h1><br>
<p class='datainf'>Return to SchoolData4all's <a href='http://".$refpage."'>WorkKeys<sup>&reg;</sup> Overall</a> Chart</p>";}

    Being not an expert on multipart email, I can't say for sure, but your content type and boundary headers look suspect to me. You have them on separate lines, and are trying to surround the boundary by quotes but have the closing quote mark on the next line. For reference, here is what I use:

    $headers .= 'Content-Type: multipart/alternative; boundary = '.$boundary."\n";

    I've tested mine with yahoo and it works. Haven't tried hotmail.

    As an aside, you do know that PEAR (example) or the PHPMailer class could make this easier on you, right?

      Ah, thanks for the fresh set of eyes on this. I've been looking at this code forever trying to figure out what was the deal. This now works in Hotmail, but the way you have it written still does not work in Yahoo for me.

      Shouldn't it be....I haven't tested this.....

      "Content-Type: multipart/alternative; boundary='".$mime_boundary."'\n";???

        Looking through the headers of my email, it does appear the boundary value should be surrounded by double quotes. I said I wasn't an expert, right? 🙂

        "Content-Type: multipart/alternative; boundary=\"".$mime_boundary."\"\n";

          Hey, even though you think you are not an expert, you were able to see something I didn't. I'm almost to the promised land on this one. I can visually see the html in hotmail, but still having problems with yahoo.

          I can see the headers coming into yahoo, but visually I can't see anything in the body of the e-mailed message. When you tested on yahoo, were you just looking at the headers or did your test involve the visual presentation of the e-mail?

          The file is about 13K, so I know the whole thing is there. I have forwarded the message from yahoo to hotmail and it will show in hotmail even if it doesn't present itself in yahoo.

          By the way, thank you very much for your insight on this.

            When I test yahoo I just do a visual test, no headers.

            I went ahead an copied your code to test. I had to add a newline before the final boundary, and make the discussed change to the content type line, but it worked fine. Here is what I ended up with:

            // E-mail Body Message
            $mime_boundary = "==Multipart_Boundary_x".md5(mt_rand())."x";
            
            $message = "Content-Transfer-Encoding: 7bit\n"
                   . "This is a multi-part message in MIME format. This part of the E-mail should never be seen. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.\n\n" 
                   . "--{$mime_boundary}\n" 
                   . "Content-Type: text/plain; charset=iso-8859-1\n" 
                   . "Content-Transfer-Encoding: 7bit\n\n" 
                   . "This is the text portion of an HTML e-mail.\n" 
                   . "--{$mime_boundary}\n" 
                   . "Content-Type: text/html; charset=iso-8859-1\n" 
                   . "Content-Transfer-Encoding: 7bit\n\n" 
                   . "<html><body><p><font color=\"red\">Sent By: Me</font><br /><br />" 
                   . "Sender's E-mail Address: [email]me@example.com[/email]<br /><br />" 
                   . "Personal Message: Testing<br /><br />" 
                   . "URL: <a href='http://www.example.com'>[url]http://www.example.com[/url]</a></p>" 
                   . "</body></html>\n" 
                   . "--{$mime_boundary}--\n";
            
            $headers  = "From: Me <me@example.com>\n";
            $headers .= "Reply-To: [email]me@example.com[/email]\n";
            $headers .= "MIME-Version: 1.0\n";
            $headers .= "Content-Type: multipart/alternative; boundary=\"".$mime_boundary."\"\n";
            
            mail('me@yahoo.com', "Test Email", $message, $headers);
            

              That's a winner! Thanks a bunch mtmosier. This was giving me fits, but it definitely works very well now in both hotmail and yahoo. As for phpmail(), I'll check into that per your recommendation.

                Write a Reply...