Forum Moderators: coopster

Message Too Old, No Replies

PHP Mail Problem

Is this a mail() problem or client problem?

         

jeffgman

7:10 pm on Aug 16, 2004 (gmt 0)

10+ Year Member



I am using the mail() command to send out an e-mail message. But, I am getting different results between two different clients. I am curious if this is a PHP problem, or just a problem with the way the clients are interpreting the headers.

Here is the code I am using:


// send the mail

// recipients

$to = "**** <****@xxx.com>, xxx <xxx@xxx.com>";

// subject

$subject = "Weekly Warehouse Supply Order";

// from

if($store == "01") {
$from = "xxx <xxx@xxx.com>";
}

// message

$message = "
<HTML>
<HEAD>
<TITLE>Weekly Store Order</TITLE>
</HEAD>
<BODY>
Weekly Store Order - Store: {$store}<BR>
Order Number - {$order_no}<BR>
Order Date - {$today}<BR>
IP Number - {$ip}<BR><BR>
<TABLE>
<TR>
<TD width=\"250\"><center><b><u>Description</u></b></center></TD>
<TD width=\"60\"><center><b><u>VPC</u></b></center></TD>
<TD width=\"60\"><center><b><u>Min</u></b></center></TD>
<TD width=\"60\"><center><b><u>Max</u></b></center></TD>
<TD width=\"80\"><center><b><u>Pkge Qty</u></b></center></TD>
<TD width=\"60\"><center><b><u>Order</u></b></center></TD>
</TR>
";

$detailqry2 = "SELECT * FROM whse_order_detail WHERE order_no = '".$order_no."' AND order_qty!= 0";

$result2=mysql_query($detailqry2, $conn);

while ($row=mysql_fetch_array($result2, $conn)) {
$order_no2=$row["order_no"];
$id_no=$row["id_no"];
$sku=$row["sku"];
$order_qty2=$row["order_qty"];
$order_date=$row["order_date"];
$store2=$row["store"];

$detailqry3 = "SELECT * FROM whse_order_items WHERE id_no = '".$id_no."'";

$result3=mysql_query($detailqry3, $conn);

while ($row=mysql_fetch_array($result3, $conn)) {
$id_no=$row["id_no"];
$sku=$row["sku"];
$description=$row["description"];
$vpc=$row["vpc"];
$package_qty=$row["package_qty"];
$location=$row["location"];
$min=$row["min"];
$max=$row["max"];

$message .= "
<TR>
<TD>{$description}</TD>
<TD>{$vpc}</TD>
<TD><center>{$min}</center></TD>
<TD><center>{$max}</center></TD>
<TD><center>{$package_qty}</center></TD>
<TD><center>{$order_qty2}</center></TD>
</TR>
";
}
mysql_free_result($result3);
}
mysql_free_result($result2);

$message .= "
<TR>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD colspan=\"6\"><textarea rows=\"5\" cols=\"80\" name=\"comment\" wrap>{$comment}</textarea></TD>
</TR>
</TABLE>
</BODY>
</HTML>
";

//To send HTML mail, you can set the Content-type header.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

//additional headers
$headers .= "To: {$from}\r\n";
$headers .= "From: {$from}\r\n";

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

?>

Here are the headers from Entourage for Mac OS X:

Return-Path: <xxx@xxx.xom>
Received: from xxxx (192.168.168.229) by xxx with
ESMTP (Eudora Internet Mail Server 3.2.5);
Sat, 14 Aug 2004 12:48:28 -0700
Received: by xxx (Postfix, from userid 70)
id 2F447131DF0; Sat, 14 Aug 2004 12:48:33 -0700 (PDT)
To: xxx <xxx@xxx.com>,
xxx <xxx@xxx.com>
Subject: Weekly Warehouse Supply Order
MIME-Version: 1.0

Content-type: text/html; charset=iso-8859-1

To: xxx <xxx@xxx.com>
From: xxxx <xxx@xxx.com>
Message-Id: <20040814194833.2F447131DF0@xxx>
Date: Sat, 14 Aug 2004 12:48:33 -0700 (PDT)

And, here are the headers using Mail.app from Mac OS X:

Return-Path: <xxx>
Received: from xxx (192.168.168.229) by xxx with
ESMTP (Eudora Internet Mail Server 3.2.5);
Sat, 14 Aug 2004 12:48:28 -0700
Received: by xxx (Postfix, from userid 70)
id 2F447131DF0; Sat, 14 Aug 2004 12:48:33 -0700 (PDT)
To: xxx <xxx>,
xxx <xxx>
Subject: Weekly Warehouse Supply Order
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
To: xxx <xxx>
From: xxx <xxx>
Message-Id: <20040814194833.2F447131DF0@xxx>
Date: Sat, 14 Aug 2004 12:48:33 -0700 (PDT)

As you can see, the Entourage headers have thrown in two extra blank lines. The client thinks the first blank line is the end of the headers and starts the message there. It ends up messing up my html mail format when this is done.

Where do you think the problem lies? With my PHP code or with the client?

Timotheos

8:10 pm on Aug 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi jeffgman,

We meet again ;-)

I'd at least try it with "\n" rather then "\r\n" at the end of you're header lines. This type of thing always seems to be a problem.

Tim

jeffgman

6:25 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



Yes, only using the "/n" appears to have fixed the problem with Entourage. Thanks for the help as always.

Jeff