So, I am trying to send a fairly simple HTML email address using PHP. I spent the last three days trying to find a good solution and I think I found it, but when I test it, it does not go out properly. I borrowed this code from one of the manuals that I referenced. The verification code is as follows:
<?php
$to = 'myemail@gmail.com';
$subject = 'Test HTML email';
$random_hash = md5(date('r', time()));
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"".$random_hash."\"";
ob_start();
?>
--<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--<?php echo $random_hash; ?>--
<?
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
The problem is that although it sends the email just fine, it either sends it as plain text or an empty message in Gmail. Any ideas why?
Bryan source
share