Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

HTML email displaying oddly with random ! in markup

the mail() function

Moderators: macek, egami, gesf

HTML email displaying oddly with random ! in markup

Postby kleinsteve » Wed May 30, 2012 3:01 pm

Hi, i have a php script that emails a long list of inventory items from a form. When i echo the results formatted as HTML it displays no problem, but when i send it in an email exclamation points will pop into the mark up throwing it out of whack. I've changed the headers a few times thinking that might be causing it, but that hasn't helped.

Here's the code i'll add an example of the html markup below it:

Code: Select all
$date_current = date('l jS \of F Y h:i:s A');
   $email_from = 'email@email.com';
   $email_subject = "Inventory " . $date_current;
   
   $email_to = "someone@somewhere.com";
   $email_headers = "From: $email_from \r\n";
   $email_headers .= "Reply-To: $to \r\n";
   $email_headers .= "MIME-Version: 1.0\r\n";
   $email_headers .= "Content-Type: text/html; charset=iso-8859-1; Content-Transfer-Encoding:7bit\r\n";
   
   $email_body = "<html><body>" ;
   $email_body .= "Current inventory as of: " . $date_current;
   $email_body .= "<table><tr><th>Item Name</th><th>Amount</th><th>Count Type</th><th>Category</th></tr>";
   
   mysql_connect("database", "name", "password") or die (mysql_error());
   mysql_select_db("name") or die (mysql_error());
   
   $result = mysql_query("SELECT * FROM item_list ORDER BY category, display_name") or die (mysql_error());
   
   while($row = mysql_fetch_array($result)){
   $email_body .= "<tr><td>" . $row['display_name'] . "</td>";
   $email_body .= "<td>" . ${"itemVar" . ($row['id'])} . "</td>";
   $email_body .= "<td>" . $row['count_type'] . "</td>";
   $email_body .= "<td>" . $row['category'] . "</td></tr>";
   }
   
   $email_body .= '</table></body></html>';
      
   //Send the email
   mail($email_to,$email_subject,$email_body,$email_headers);
   
   include "completed.php";


Code: Select all
<html>
<body>
<table>
<tr><th>Item Name</th><th>Amount</th><th>Count Type</th><th>Category</th></tr>
<tr><td>Aranciata</td><td>45</td><td>Eaches</td><td>Beverages</td></tr>
<tr><td>Bottled Water</td><td>45</td><td>Eaches</td><td>Beverages</td></tr>
<tr><td>Coke</td><td>45</td><td>Eaches</td><td>Beverages</td></tr>
<tr><td>Diet Coke</td><td>45</td><td>Eaches</td><td>Beverages</td></tr>
<tr><td>Limonata</td><td>45</td><td>Eaches</td><td>Beverages</td></tr>
<tr><td>Sprite</td><td>45</td><td>Eaches</td><td>Beverages</td></tr>
<tr><td>Bleach</td><td>89</td><td>Quarts</td><td>Cleaning</td></tr>
<tr><td>C-Fold Towels</td><td>89</td><td>Packs</td><td>Cleaning</td></tr>
<tr><td>Dish Soap</td><td>89</td><td>Quarts</td><td>Cleaning</td></tr>
<tr><td>Dish Towels</td><td>89</td><td>Eaches</td><td>Cleaning</td></tr>
<tr><td>Gloves</td><td>89</td><td>Boxes</td><td>Cleaning</td></tr>
<tr><td>Hand Soap</td><td>89</td><td>Quarts</td><td>Cleaning</td></tr>
<tr><td>!Quaternery Strips</td><td>89</td><td>Packs</td><td>Cleaning</td></tr>
<tr><td>Santimine Tablets</td><td>89</td><td>Bottles</td><td>Cleaning</td></tr>
<tr><td>Trash Bags</td><td>89</td><td>Boxes</td><td>Cleaning</td></tr>
<tr><td>Bagels & Butter</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Bagels & Cream Cheese</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Balsamic Vinaigrette</td><td>5</td><td>Eaches</td><td>Food</t></tr>
<tr><td>Caesar Dressing</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Caprese Wrap</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Ceasar Chicken Wrap</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Chili Vinaigrette</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Cream</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Half & Half</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Hot Dog Buns</td><td>5</td><td>Packs</td><td>Food</td></tr>
<tr><td>Hot Dogs</td><td>5</td><td>Packs</td><td>Food</td></tr>
<!tr><td>Lemon Juice</td><td>5</td><td>Quarts</td><td>Food</td><!/tr>
<tr><td>Lemons</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Lobster Salad</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Mac N' Cheese</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Milk Fat Free</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Milk Soy</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Milk Whole</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Packets Equal</td><td>5</td><td>Bags</td><td>Food</td></tr>
<tr><td>Packets Ketchup</td><td>5</td><td>Bags</td><td>Food</td></tr>
<tr><td>Packets Regular Sugar</td><td>5</td><td>Bags</td><td>Food</td></tr>
<tr><td>Packets Relish</td><td>5</td><td>Bags</td><td>Food</td></tr>
<tr><td>Packets Splenda</td><td>5</td><td>Bags</td><td>Food</td></tr>
<tr><td>Packets Yellow Mustard</td><td>5</td><td>Bags</td><td>Food</td></tr>
<tr><td>Potato Chips Garlic & Dill</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Potato Chips Spicy Dill</td><td>5</td><td>Eaches</td><td>Food</td></tr>!
<tr><td>Sauerkraut</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Sloppy Joe</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Sugar</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Vietnamese Chicken Wrap</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>Watermelon Cups</td><td>5</td><td>Eaches</td><td>Food</td></tr>
<tr><td>White Onion Raw Diced</td><td>5</td><td>Quarts</td><td>Food</td></tr>
<tr><td>Bond Paper (Kitchen Chits)</td><td>12</td><td>Eaches</td><td>Paper Goods</td></tr>
<tr><td>Debbie Bags</td><td>12</td><td>Eaches</td><td>Paper Goods</td></tr>
<tr><td>Foil Sheets</td><td>12</td><td>Boxes</td><td>Paper Goods</td></tr>
<tr><td>Kraft Napkins</td><td>12</td><td>Packs</td><td>Paper Goods</td></tr>
<tr><td>Thermal Paper (Receipts)</td><td>12</td><td>Eaches</td><td>Paper Goods</td></tr>
<tr><td>Greenware Cup Lids</td><td>32</td><td>Sleeves</td><td>Smallwares</td></tr>
<tr><td>Greenware Cups</td><td>32</td><td>Sleeves</td><td>Smallwares</td></tr>
<tr><!td>Hot Dog Boxes</td><td>32</td><td>Sleeves</td><td>Smallwares!</td></tr!>
<tr><td>Paper Cup Lids</td><td>32</td><td>Sleeves</td><td>Smallwares</td></tr>
<tr><td>Paper Cups (sides)</td><td>32</td><td>Sleeves</td><td>Smallwares</td></tr>
<tr><td>Straws</td><td>32</td><td>Boxes</td><td>Smallwares</td></tr>
</table>
</body>
</html>


There aren't many of them, but just enough to cause the HTML to display improperly.
kleinsteve
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun May 27, 2012 1:18 pm

Re: HTML email displaying oddly with random ! in markup

Postby Nullsig » Thu May 31, 2012 4:56 am

<!tr><td>Lemon Juice</td><td>5</td><td>Quarts</td><td>Food</td><!/tr>

That looks to be your problem.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: HTML email displaying oddly with random ! in markup

Postby Nullsig » Thu May 31, 2012 4:56 am

And this line:
<tr><td>!Quaternery Strips</td><td>89</td><td>Packs</td><td>Cleaning</td></tr>
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: HTML email displaying oddly with random ! in markup

Postby kleinsteve » Thu May 31, 2012 6:19 am

Right, but the script above is generating that. I can't find any reason for it to print those exclamation points. They turn up in various places everytime I run the script.
kleinsteve
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun May 27, 2012 1:18 pm

Re: HTML email displaying oddly with random ! in markup

Postby Nullsig » Thu May 31, 2012 6:27 am

I personally have never experienced this. It does seem that the issue is caused by excessive line length in your HTML code.

From this article:http://stackoverflow.com/questions/7921111/exclamation-point-in-html-email

It seems like that would be a solution. My suspicion is that there is an easier solution for you though.

Try changing the while block of your code to this:
Code: Select all
while($row = mysql_fetch_array($result)){
   $email_body .= "<tr><td>" . $row['display_name'] . "</td>";
   $email_body .= "<td>" . ${"itemVar" . ($row['id'])} . "</td>";
   $email_body .= "<td>" . $row['count_type'] . "</td>";
   $email_body .= "<td>" . $row['category'] . "</td></tr>\r\n";
   }
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: HTML email displaying oddly with random ! in markup

Postby kleinsteve » Thu May 31, 2012 10:32 am

Brilliant. Yep, it was just that the length was too long, if you were to go through and count it out, an ! appeared after a certain number of characters throughout.

Adding the \r\n was a simple enough fix versus changing the encoding.

thanks!
kleinsteve
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun May 27, 2012 1:18 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron