Magento: mini_sendmail and Zend_Mail incompatibility Version II.

This article is now deprecated and the issue has been resolved without changes to core code after our service change.

We have recently spotted an issue after traversing our Apache sendmail application to mini_sendmail (read more about the change).

In Magento's mail headers, the recipient and sender details have both the email address and respective name, however, this breaks compatibility with mini_sendmail.

As mini_sendmail does not support anything other than just the email address alone for the recipient/sender, emails from Magento will fail to send.

As a temporary measure a fix can be issued in the form of editing core code.

1) Enter the root directory of your Magento store and enter

cp lib/Zend/Mail.php lib/Zend/Mail.orig.php
2) Using your favourite editor open up lib/Zend/Mail.php and replace the functions with this newer code

Line 447 > 469

protected function _addRecipientAndHeader($headerName, $name, $email)
{
    $email = strtr($email,"rnt",'???');
    $this->_addRecipient($email, ('To' == $headerName) ? true : false);
    if ($name !== '' && $name !== null && $name !== $email) {
        $encodedName = $this->_encodeHeader($name);
        if ($encodedName === $name && strpos($name, ',') !== false) {
                # mini_sendmail fix
                # $format = '"%s" <%s>';
            $format = '%s';
        } else {
              # mini_sendmail fix
                # $format = '%s <%s>';
            $format = '%s';
        }
        # mini_sendmail fix
        # $destination = sprintf($format, $encodedName, $email);
        $destination = sprintf($format, $email);
    } else {
        $destination = $email;
    }
    $this->_storeHeader($headerName, $destination, true);
}

Line 527 >558

public function setFrom($email, $name = null)
{
    if ($this->_from === null) {
        $email = strtr($email,"rnt",'???');
        $this->_from = $email;
        if ($name !== null && $name !== $email) {
            $encodedName = $this->_encodeHeader($name);
            if ($encodedName === $name && strpos($name, ',') !== false) {
                    # mini_sendmail fix
                    # $format = '"%s" <%s>';
                $format = '%s';
            } else {
                    # mini_sendmail fix
                    # $format = '%s <%s>';
                $format = '%s';
            }
            # mini_sendmail fix
            # $from = sprintf($format, $encodedName, $email);
            $from = sprintf($format, $email);
        } else {
            $from = $email;
        }
        $this->_storeHeader('From', $from, true);
    } else {
        /**
         * @see Zend_Mail_Exception
         */
        #require_once 'Zend/Mail/Exception.php';
        throw new Zend_Mail_Exception('From Header set twice');
    }
    return $this;
}

3) Recompile (if using extension) to update includes

You can also download the whole version of this file lib/Zend/Mail.php

This is a much better solution to the previous fix and doesn't require changes to core code, so you can upgrade with peace of mind.