I'm sending an html email via the php mail function but noticed that when the emails are received i sometimes find that spaces have been inserted within tags. For example where i have <table> somehow it becomes < table> when it arrives at the clients mailbox which causes it to be treated as text. I have reviewed my code and am even displaying the html output on the website (that instigates the call to the mail function). Whats strange is when i review the code in the browser no extra spaces have been added. I am also loggin the html email string in a database and again found that these spaces do not exist. I have considered using the strip white space function but i have text within my html table wherby the spaces need to be preserved. Typicaly the length of the html string (sent in the email) is arround 1500 characters. Perhaps the strangest thing of all is that this happens very occasionally making the cause difficult to track down. Has anyone encountered a similar problem and what steps did you take to resolve this issue. My mailing code... function emailorder($htmlOrder){ $username = $_SESSION['username']; $to = "info@swanwebtech.co.uk,officecare.co.uk," . getuseremail(); $subject = "Online Order [Office Care Services ltd User : " . $username . "]"; $orderheader = orderheader(); $message = $orderheader . $htmlOrder; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: <purchaseorder@swanwebtech.co.uk>' . "\r\n"; $headers .= 'Cc: nationwide@swanwebtech.co.uk' . "\r\n"; mail($to,$subject,$message,$headers); }
The $to = ... line looks a bit suspect. The second entry is not an email address although I don't think that would be the problem. Seeing the contents or example contents of $message would help. A thought, is $message a full html message with all the tags etc ... :
Thanks for the reply. I have since corrected the $to but its made no difference. This is not a full html message below is a typical example of what the html conntent - $message contains. Do i need to include html headers? Maybe this is my problem. <div style="color : #FF9933;" align="center"><h3>HALFORDS ORDER FORM</h3></div><table width="515"><tr><td valign ="top"><table><tr><td><b>OFFICE CARE SERVICES</b></td></tr><tr><td><b></b></td></tr><tr><td><b></b></td></tr><tr><td><b></b></td></tr><tr><td><b></b></td></tr></table></td><td valign ="top"><table><tr><td><b>A/C: 45944</b></td></tr><tr><td><b>Delivery To:</b><br/></td><td></td></tr><tr><td></td><td><b>Company : test</b></td></tr><tr><td></td><td><b>test</b></td></tr><tr><td></td><td><b>test</b></td></tr><tr><td></td><td><b>test</b></td></tr><tr><td></td><td><b>Postcode : test</b></td></tr><tr><td></td><td><b>DP : 666</b></td></tr><tr><td></td><td><b>Tel : 0000000000000</b></td></tr><tr><td></td><td><b>Date : 13/08/2008</b></td></tr></table></td><td valign ="top"><table><tr><td><b></b></td></tr><tr><td><b></b></td></tr><tr><td><b></b></td></tr><tr><td><b></b></td></tr><tr><td><b></b></td></tr></table></td></tr></table><div align="left"><table width="515" border="1" cellspacing="0" cellpadding="0"><tr bgcolor="yellow"><th>Product Code</th><th>Product Description</th><th>Unit</th><th>Price £</th><th>QTY</th></tr><tr><td>33881</td><td>7250 WYPALL L20 C-FEED 1P BLUE</td><td>6x400sh</td><td>12.23</td><td>1</td></tr><tr><td>55393</td><td>CLEAR SACK 16x25x39</td><td>1x200</td><td>13.44</td><td>2</td></tr><tr><td>63000</td><td>TRIGGER SPRAY BOTTLE 600ML COMPLETE</td><td>1</td><td>1.15</td><td>1</td></tr><tr style="color : #0000AA; font-weight:bold; font-size :14px" ><td colspan="4" align="right"><b>ORDER TOTAL </b></td><td><b> £40.26</b></td></tr></table></div>
I would include the html header etc ... just checked a few emails from some newsletters that I subscribe to and they include them plus checked the source of a couple of programs we use to create campaigns and autoresponders and they also include them.