Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP HTML Mail() scripts sent as plain text

Status
Not open for further replies.

Muppsy007

Programmer
Apr 4, 2003
98
NZ
Hi,

I'm not sure if sendmail is the problem here, but this is my last avenue after searching for almost two weeks for answers based on PHP and Qmail threads.

I was hoping someone may have seen this before, so here is the situation.

We have two PHP mail scripts running on our site at "Host A". One script sends submitted form data to us here, the other, a nicely formatted HTML confirmation to the user. (Yes I know how much HTML mail suck, but the boss loves them)

This whole setup on "Host A" worked perfectly without a hitch.

We now have upgraded to a dedicated server at "Host B", runing FreeBSD 4.8, Apache, Qmail and PHP.

A copy of the site has been moved there and the scripts tested with no changes made to the scripts.

This is what happens when the forms are submitted from "Host B":

1. When testing and entering a "client" email that resides on the same server (ie. my own), the HTML email is displayed in code only, and most of the headers displayed in the content.

2. If sent to my own Hotmail account, the HTML emails work fine.

3. If sent to my personal account, a different server in New Zealand which I access through neomail web mail, The HTML email is displayed in code only (The same as 1. above), but the formatted email is there as an attachment.


The obvious first choice was looking at the scripts, but like I said, they worked perfectly fine on the "Host A". We confirmed this when we wrote a tiny "Hello World" HTML mail() script, which had the same results as above.

It is definately not the clients, as this problem does not occur on those clients when the emails are sent from "Host A"

If it's worth anything, I managed to get the simple script working by commenting out the header entry:

Code:
$headers  = "MIME-Version: 1.0\r\n";

And making sure this header entry was appended last (after "To: ", "CC: " etc):

Code:
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

My Host has very good support, but they are as bamboozled as me, and I have not found anything on the Net in 8 days of searching, but tend to get warmer when looking at sendmail.

Has anyone seen this before? Ideas? I will personally send a nice cold pint of beer to the person who finally ends this nightmare for me.

Cheers
Aaron

 
Just a note, sendmail isn't at issue here--you're not even using it on "host B" per your posted information (FreeBSD 4.8, Apache, Qmail and PHP.)

That said, I'd say you're definitely on the right track with your test program. Everytime I've seen a similar problem it's because of something breaking the MIME encoding.

How about posting your scripts and some sample output?
 
Hi jkupski,

Thanks for the response. I'm not really sure how sendmail works, or what the mail() function uses to send mail, but I was under the impression that sendmail was something that such scripts used to send mail from the site.

Anyway, Here is the simple test script and output. I won't post the main script, as it huge.

Code:
<?php
/* recipients */
$to  = "me@mysite.co.uk";


/* subject */
$subject = "HTML email from Old Server";

/* message */
$message = '
<html>
<head>
 <title>This is an HTML Message</title>
</head>
<body>
<p>This is my shopping list</p>
<table>
 <tr>
  <th>Item</th><th>Quantity</th><th>Price</th><th>Coupon</th>
 </tr>
 <tr>
  <td>Bread</td><td>2</td><td>£1.60</td><td>no</td>
 </tr>
 <tr>
  <td>Milk</td><td>1</td><td>£0.99</td><td>yes</td>
 </tr>
</table>
</body>
</html>
';

/* To send HTML mail, you can set the Content-type header. */

// TEK-TIP Note: If you comment out the below line, and move the "Content-type" line below the last $header append (From). Everything Works //

$headers  = "MIME-Version: 1.0\r\n";  
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Aaron <me@mysite.co.uk>\r\n";
$headers .= "From: Shopping List <script@mysite.co.uk>\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>

And here is the output of this email when sent to an address located on the same server:

Content-type: text/html; charset=iso-8859-1
To: Aaron <me@mysite.co.uk>
From: Shopping List <script@mysite.co.uk>



<html>
<head>
<title>This is an HTML Message</title>
</head>
<body>
<p>This is my shopping list</p>
<table>
<tr>
<th>Item</th><th>Quantity</th><th>Price</th><th>Coupon</th>
</tr>
<tr>
<td>Bread</td><td>2</td><td>£1.60</td><td>no</td>
</tr>
<tr>
<td>Milk</td><td>1</td><td>£0.99</td><td>yes</td>
</tr>
</table>
</body>
</html>

This email also comes in twice, as the headers are not working.

If this same script is run on "Host A", or if the message is sent to an external address (at least so it seems but one of my main concerns), we get this email:

This is my shopping list

Item Quantity Price Coupon
Bread 2 £1.60 no
Milk 1 £0.99 yes

NOTE this email is formatted bold/table etc. It also only comes in once as the headers are working.

Thanks
Aaron
 
If it helps, I have managed to get the following header info from the incorrect email:

Return-path: <anonymous@mysite.co.uk>
Envelope-to: aaron@nemesis.co.nz
Delivery-date: Sat, 18 Dec 2004 05:52:02 +1300
Received: (helo=ds303.dedicated.turbodns.co.uk)
by genamics.blastula.net with esmtp (TLSv1:DES-CBC3-SHA:168)
(Exim 4.34)
id 1CfLKf-0007sM-QZ
for aaron@nemesis.co.nz; Sat, 18 Dec 2004 05:51:58 +1300
Received: (qmail 74131 invoked by uid 2010); 17 Dec 2004 16:52:41 -0000
Date: 17 Dec 2004 16:52:41 -0000
Message-ID: <20041217165241.74130.qmail@idhost>
X-DHSource: /execscriptdir/php.cgi
X-DHSender: 81.136.215.235
To: aaron@nemesis.co.nz
Subject: Order
From: me@mysite.co.uk (Orders System)
MIME-Version: 1.0 (produced by FormMail 2.15 from Content-Type: multipart/alternative; boundary="BODYc8105374c9db32f3c9819201817cfa1c"
X-MailScanner-Information: Please contact the ISP for more information
X-MailScanner: Found to be clean
 
Long shot, but do you allow your mailscanner to pass html messages? I see that it is being scanned with the X-MailScanner headers being added.

Keith

 
Found the Solution to this problem in case anyone else has the same issues.

With FreeBSD (the server I am using) all new lines in PHP Mail headers MUST end with "\n" not "\r\n" as per usual.

After I did a big serach and replace for this, we were away laughing.

Seems to only affect FreeBSD.

Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top