Php – Weird Postfix fatal error

PHPpostfixzend-framework

I run three Magento web stores. All the orders e-mails are working just fine, with the exception of 7 e-mails that didn't even got sent from the webserver. Upon investigating the issue I discovered the following logs:

Magento log:

2013-08-08T11:44:59+00:00 ERR (3): 
exception 'Zend_Mail_Transport_Exception' with message 'Unable to send mail. ' in /var/www/website.com/lib/Zend/Mail/Transport/Sendmail.php:137

Postifx log:

Aug  8 12:44:59 bv-webserver postfix/sendmail[18647]: fatal: sales@website.com(33): No recipient addresses found in message header
Aug  8 12:44:59 bv-webserver postfix/postdrop[18648]: fatal: uid=33: malformed input

This is very strange, because hundreds of e-mails were sent just fine and only these 7 got this exception. In some cases the clients just purchased again from the store and then received the e-mail as expected.

I thought it could be a resource problem. But I run the newrelic agent and the server is at 20% load at most during peak hours (both memory and processors).

Edit: Forgot to mention, I run nginx with php-fpm.

Best Answer

postdrop[18648]: fatal: uid=33: malformed input

This say it all, you have 7 emails that are broken. They probably have a line feed/carrier return , making the headers finish too soon (probably before the To: header).

That line feed might be in the start of the recipient address (so the to: is null) or on in any previous user input strings. That line feed might also not be visible in many situations (stripped, form without scrool bar, replaced by space on output, etc), so search carefully.

try checking the /var/spool/postfix/maildrop/ folders for the bad emails, it should be empty, but give it a try...

you probably need to put postdrop in debug, add a -v in the end of the postdrop line in the master.cf

check the postdrop man page for more info