I am going to try this one more time with a very basic example. When I send an e-mail using PHP to e-mail clients, I have no problem except with gmail. When I view the e-mail in gmail, all I see is the code of the message. Gmail does not display the HTML. It just displays the code. Here is my script:
<?php
$to = "someone@gmail.com";
$subject = "Test HTML E-mail";
$random_hash = md5(date("r", time()));
$mID = md5($to);
$headers = "From: admin@yellowcas.com" . "
" . "Reply-To: admin@yellowcas.com" . "
";
$headers .= "Errors-To: someone@yahoo.com" . "
";
$headers .= "MIME-Version: 1.0" . "
";
$headers .= "Content-Type: multipart/alternative; boundary=". $random_hash ." ; Message-ID: <" . $mID . ">" . "
";
ob_start();
?>
--<?php echo $random_hash; ?>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello, Tom!!!
This is simple text email message.
--<?php echo $random_hash; ?>
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
<!doctype html>
<head>
<title>Untitled Document</title>
</head>
<body>
<h2>Hello, Tom!</h2>
<p>This is something with <strong>HTML</strong> formatting.</p>
</body>
</html>
--<?php echo $random_hash; ?>--
<?php
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
I have tried this script without the DOCTYPE and with the DOCTYPE. I do not believe there is anything wrong with the HTML. I believe gmail is not recognizing the boundary string for some reason. Here is what I see when I open the e-mail:
--111f3d21df6a6eb40a42e9337a600c21
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello, Tom!!!
This is simple text email message.
--111f3d21df6a6eb40a42e9337a600c21
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
<!doctype html>
<head>
<title>Untitled Document</title>
</head>
<body>
<h2>Hello, Tom!</h2>
<p>This is something with <strong>HTML</strong> formatting.</p>
</body>
</html>
--111f3d21df6a6eb40a42e9337a600c21--
Can anyone PLEASE tell me why gmail is rendering the whole message and not encoding the HTML? It is as if gmail does not recognize the boundary string. How do I fix this?
As a side note, yes, this is a basic PHP e-mail script I found on the internet. I have made a few modifications, but it is still not working in gmail. All other e-mail clients render it fine. PLEASE HELP! I am at my wit's end. Thank you.
When I added the $headers line in the code example right below that was submitted by Fred -ii-, gmail rendered the HTML, but it still shows the boundary string and the plain text message also. This is what the e-mail looks like:
--f8451c07b6649388e8938cfa12ea21e6 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Hello, Greg!!! This is simple text email message. --f8451c07b6649388e8938cfa12ea21e6 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bitHello, Tom!
This is something with HTML formatting. --f8451c07b6649388e8938cfa12ea21e6--
I hope that comes out right.