Thursday, August 25, 2005

Zen Cart email woes with Postfix MTA

I've been working on setting up a Zen Cart shopping cart on my companies web server.

The installation was easy, however I've been having trouble with the formatting of the emails sent from the shopping cart to my test customer accounts and the emails sent to my admin email account.

The emails are supposed to show up as HTML emails, instead they show up as text with all the HTML code in the body of the email. If I change to Text only emails, the body of the email doesn't have any line breaks.

Here's a sample

Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit
Order Confirmation from My Store John Doe Thanks for shopping with us today! The following are the details of your order.
------------------------------------------------------ Order Number: 8 Date Ordered: Tuesday 23 August, 2005 Detailed Invoice: https://www.mystore.com/catalog/index.php?m...info&order_id=8 Please ship it -1 day air! Well, it's not here yet.
I couldn't find any love on the Zen Cart site, although I did get someone who responded with "I'm having the same problem".

I google'd around and came across this page on Php.net, and this particular entry:
php at richardneill dot org
12-Jul-2004 07:09
Postfix under Mandrake 10.0 also objects to \\r\\n. The result is that every email is double-spaced, and all attachments break. (it was OK in 9.1). My (short-term) fix is this:

$message = str_replace("\r",'',$message);

This discussion may be relevant:
http://www.phpdiscuss.com/article.php?id=60615&group=php.bugs
So, I started grep'n and found this file: $wwwroot/catalog/includes/classes/email.php

I made the following change to the sendmail portion of the code (the comments are the original code):

if (EMAIL_FRIENDLY_ERRORS=='true') {
//return @mail($to, $subject, preg_replace("#(?<!\r)\n#s","\r\n", $this->output), $headers_list);
return @mail($to, $subject, preg_replace("#(?<!\r)\n#s","\n", $this->output), $headers_list);
} else {
//return mail($to, $subject, preg_replace("#(?<!\r)\n#s","\r\n", $this->output), $headers_list);
return mail($to, $subject, preg_replace("#(?<!\r)\n#s","\n", $this->output), $headers_list);
}
Notice that I simply replaced "\r\n" with "\n".

Preliminary tests have shown that this change has fixed the problem with the HTML and Plain Text emails.

0 Comments:

Post a Comment

<< Home