title: Gmail will not render HTML email using PHP
body: <p>I have been trying to get gmail to render the html contents of an e-mail I send to it, but it just gives me the complete text of the e-mail. When i send an e-mail to yahoo or my e-mail address at comcast.net, I have no problem seeing the html e-mail part. Gmail renders the whole thing including the boundary string. This is my code below:</p>
  
  <pre><code>//  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 = "MIME-Version: 1.0\r\n";
  $headers .= "From: \"" . $replyToName . "\" &lt;" . $replyTo . "&gt;\r\nReply-To: " . $replyTo . "\r\n";
  $headers .= "X-Mailer: PHP/" . phpversion();
  //  Add boundary string and mime type specification
  $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-" . $random_hash ."\"";
  $headers .= "\r\n";
  //This is the plain-text part of the e-mail. This is what the recipient will see if they can only receive text-only e-mails.
  ?&gt;
  --PHP-alt-&lt;?php echo $random_hash; ?&gt; 
  Content-Type: text/plain; charset="utf-8"
  Content-Transfer-Encoding: 7bit
  
  &lt;?php echo $plainMsg; ?&gt;
  
  &lt;?php echo $mainSite; ?&gt;
  ______________________________________________________
  
  This e-mail is intended for the eyes of the recipient only. If you are not the
  intended recipient, please send an e-mail to &lt;?php echo $replyTo; ?&gt; to inform us of
  the mistake, and please destroy any and all copies of this e-mail.
  
  --PHP-alt-&lt;?php echo $random_hash; ?&gt; 
  Content-Type: text/html; charset="utf-8"
  Content-Transfer-Encoding: 7bit
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs"&gt;
  &lt;head&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;table width="100%" border="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0" bgcolor="#ADD8E6"&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;img src="&lt;?php echo $mainLink; ?&gt;/images/BF.gif" width="95" height="65"&gt;&lt;/td&gt;
  &lt;td valign="top"&gt;&lt;img src="&lt;?php echo $imageLink; ?&gt;" width="&lt;?php echo $imageWidth; ?&gt;" height="&lt;?php echo $imageHeight; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;font face="Arial, Helvetica, sans-serif" size="2"&gt;
  &lt;?php echo $mailMsg; ?&gt;
  &lt;/font&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;p&gt;
  &lt;font face="Arial, Helvetica, sans-serif" size="2"&gt;
  &lt;a href="&lt;?php echo $mainLink; ?&gt;"&gt;&lt;?php echo $mainSite; ?&gt;&lt;/a&gt;
  &lt;/font&gt;
  &lt;br /&gt;
  ______________________________________________________
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;font face="Arial, Helvetica, sans-serif" size="1"&gt;
  This e-mail is intended for the eyes of the recipient only. If you are not the intended recipient, please send an e-mail to &lt;a href="mailto:&lt;?php echo $replyTo; ?&gt;"&gt;&lt;?php echo $replyTo; ?&gt;&lt;/a&gt; to inform us of the mistake, and please destroy any and all copies of this e-mail.
  &lt;/font&gt;
  &lt;/p&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0" bgcolor="#ADD8E6"&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;
  &lt;font size="-2"&gt;All content, images, and data &amp;#0169; Bright Futures 2009-2014.
  &lt;br /&gt;
  All rights reserved.&lt;/font&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  --PHP-alt-&lt;?php echo $random_hash; ?&gt; --
  </code></pre>
  
  <p>When I send this e-mail,  I see the whole message not encoded. It shows me the boundary string and the html tags in the message. When I go to "Show Original" in gmail, I get the following:</p>
  
  <pre><code>Delivered-To: gsg1175@gmail.com
  Received: by 10.182.23.6 with SMTP id i6csp32095obf;
          Wed, 19 Feb 2014 01:03:00 -0800 (PST)
  X-Received: by 10.68.106.130 with SMTP id gu2mr924626pbb.59.1392800580001;
          Wed, 19 Feb 2014 01:03:00 -0800 (PST)
  Return-Path: &lt;gsg1175@p3plcpnl0157.prod.phx3.secureserver.net&gt;
  Received: from m1plded02-04.prod.mesa1.secureserver.net (m1plded02-04.prod.mesa1.secureserver.net. [64.202.189.17])
          by mx.google.com with ESMTP id ri10si3237317pbc.297.2014.02.19.01.02.59
          for &lt;gsg1175@gmail.com&gt;;
          Wed, 19 Feb 2014 01:02:59 -0800 (PST)
      Received-SPF: pass (google.com: domain of gsg1175@p3plcpnl0157.prod.phx3.secureserver.net designates 64.202.189.17 as permitted sender) client-ip=64.202.189.17;
  Authentication-Results: mx.google.com;
         spf=pass (google.com: domain of gsg1175@p3plcpnl0157.prod.phx3.secureserver.net designates 64.202.189.17 as permitted sender) smtp.mail=gsg1175@p3plcpnl0157.prod.phx3.secureserver.net
  Received: from p3plcpnl0157.prod.phx3.secureserver.net ([184.168.200.188])
      by m1plded02-04.prod.mesa1.secureserver.net with : DED :
      id U92x1n01E44PGPL0192x1U; Wed, 19 Feb 2014 02:02:59 -0700
  Received: from gsg1175 by p3plcpnl0157.prod.phx3.secureserver.net with local (Exim 4.82)
      (envelope-from &lt;gsg1175@p3plcpnl0157.prod.phx3.secureserver.net&gt;)
      id 1WG33R-001P1W-8P; Wed, 19 Feb 2014 02:02:57 -0700
  To: gsg1175@gmail.com,g.greenwell@comcast.net
  Subject: Test E-mail
  X-PHP-Script: www.yellowcas.com/sendemail.php for 107.4.20.247
  MIME-Version: 1.0
  From: "Gregory Greenwell" &lt;admin@yellowcas.com&gt;
  Reply-To: admin@yellowcas.com
  CC: looking4unabq@yahoo.com
  X-Mailer: PHP/5.4.23
  Content-Type: multipart/alternative; boundary="PHP-alt-8d0c53f7f76522e3a03197894d7e89fe"
  Message-Id: &lt;E1WG33R-001P1W-8P@p3plcpnl0157.prod.phx3.secureserver.net&gt;
  Date: Wed, 19 Feb 2014 02:02:57 -0700
  X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
  X-AntiAbuse: Primary Hostname - p3plcpnl0157.prod.phx3.secureserver.net
  X-AntiAbuse: Original Domain - gmail.com
  X-AntiAbuse: Originator/Caller UID/GID - [267295 956] / [47 12]
  X-AntiAbuse: Sender Address Domain - p3plcpnl0157.prod.phx3.secureserver.net
  X-Get-Message-Sender-Via: p3plcpnl0157.prod.phx3.secureserver.net: authenticated_id: gsg1175/from_h
  X-Source: 
  X-Source-Args: /usr/sbin/proxyexec -q -d -s /var/run/proxyexec/cagefs.sock/socket /bin/cagefs.server 
  X-Source-Dir: yellowcas.com:/public_html
  
  
  --PHP-alt-8d0c53f7f76522e3a03197894d7e89fe 
  Content-Type: text/plain; charset="utf-8" 
  Content-Transfer-Encoding: 7bit 
  
  We will keep doing this until we get it right!
  
  Why won't this work?
  
  WWW.YELLOWCAS.COM
  ______________________________________________________
  
  This e-mail is intended for the eyes of the recipient only. If you are not the intended recipient, please send an e-mail to admin@yellowcas.com to inform us of the mistake, and please destroy any and all copies of this e-mail.
  
  --PHP-alt-8d0c53f7f76522e3a03197894d7e89fe 
  Content-Type: text/html; charset="utf-8" 
  Content-Transfer-Encoding: 7bit 
  
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs"&gt;
  &lt;head&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;table width="100%" border="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0" bgcolor="#ADD8E6"&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;img src="https://www.yellowcas.com/images/BF.gif" width="95" height="65"&gt;&lt;/td&gt;
  &lt;td valign="top"&gt;&lt;img src="https://www.yellowcas.com/images/brightfutures70.gif" width="520" height="60" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;font face="Arial, Helvetica, sans-serif" size="2"&gt;
  We will keep doing this &lt;b&gt;until we get it right!&lt;/b&gt;
  
  Why won't this work?
  &lt;/font&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;p&gt;
  &lt;font face="Arial, Helvetica, sans-serif" size="2"&gt;
  &lt;a href="https://www.yellowcas.com"&gt;WWW.YELLOWCAS.COM&lt;/a&gt;
  &lt;/font&gt;
  &lt;br /&gt;
  ______________________________________________________
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;font face="Arial, Helvetica, sans-serif" size="1"&gt;
  This e-mail is intended for the eyes of the recipient only. If you are not the intended recipient, please send an e-mail to &lt;a href="mailto:admin@yellowcas.com"&gt;admin@yellowcas.com&lt;/a&gt; to inform us of the mistake, and please destroy any and all copies of this e-mail.
  &lt;/font&gt;
  &lt;/p&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0" bgcolor="#ADD8E6"&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;
  &lt;font size="-2"&gt;All content, images, and data &amp;#0169; Bright Futures 2009-2014.
  &lt;br /&gt;
  All rights reserved.
  &lt;/font&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  --PHP-alt-8d0c53f7f76522e3a03197894d7e89fe-- 
  </code></pre>
  
  <p>I apologize for this being so long, but I cannot figure out why gmail is not displaying the html as html. I am using the php mail() function to send the e-mail. Every other e-mail client I have looked at renders the html just fine, but gmail just displays the underlying code in the e-mail. If ANYONE has ANY ideas, I would be very appreciative to hear them. Thank you for taking the time to review my code. </p>