magento order email

Magento Order email not sent but cron job running | exception ‘Zend_Mail_Transport_Exception’ with message ‘Missing To header’ in /var/www/html/shop/lib/Zend/Mail/Transport/Sendmail.php:182

Solution 1

Are you getting following message in your magento shop /var/exception.log

2015-10-28T00:05:02+00:00 ERR (3):
exception 'Zend_Mail_Transport_Exception' with message 'Missing To header' in /var/www/html/shop/lib/Zend/Mail/Transport/Sendmail.php:182
Stack trace:
#0 /var/www/html/shop/lib/Zend/Mail/Transport/Abstract.php(337): Zend_Mail_Transport_Sendmail->_prepareHeaders(Array)
#1 /var/www/html/shop/lib/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#2 /var/www/html/shop/app/code/core/Mage/Core/Model/Email/Queue.php(236): Zend_Mail->send()
#3 [internal function]: Mage_Core_Model_Email_Queue->send(Object(Mage_Cron_Model_Schedule))
#4 /var/www/html/shop/app/code/core/Mage/Cron/Model/Observer.php(326): call_user_func_array(Array, Array)
#5 /var/www/html/shop/app/code/core/Mage/Cron/Model/Observer.php(72): Mage_Cron_Model_Observer->_processJob(Object(Mage_Cron_Model_Schedule), Object(Mage_Core_Model_Config_Element))
#6 /var/www/html/shop/app/code/core/Mage/Core/Model/App.php(1357): Mage_Cron_Model_Observer->dispatch(Object(Varien_Event_Observer))
#7 /var/www/html/shop/app/code/core/Mage/Core/Model/App.php(1336): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Cron_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#8 /var/www/html/shop/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('default', Array)
#9 /var/www/html/shop/cron.php(77): Mage::dispatchEvent('default')
#10 {main}
As you might understand that the problem is due to sender missing. But, in Magento 1.9, this is serious problem as it might stop all your order emails to stop sending. The solution is finding the order with the null email address and deleting the email_queue cron job of that order. Here are the tricks

First find the order that have no email with following command

 FROM `sales_flat_order`
 WHERE `customer_email` IS NULL

Now I recommend to update that order

UPDATE `sales_flat_order` SET `customer_email` = '*******' WHERE `sales_flat_order`.`entity_id` =YOUR_ORDER_ID ;

Now find this order in core_email_queue

select * from `core_email_queue` WHERE entity_id='YOUR_ORDER_ID'; ///Note this is not order number. 
////you can get order id from the url of admin of order

There should be 2 entries if you send yourself as well order copy

And now find the corresponding in core_email_queue_recipients

select * from `core_email_queue_recipients` WHERE message_id='MESSAGE_ID_FROM_core_email_queue'
select * from `core_email_queue_recipients` WHERE message_id='MESSAGE_ID_FROM_core_email_queue'

If you do not have message_id in core_email_queue_recipients, then you should delete it from core_email_queue


DELETE FROM core_email_queue WHERE message_id='MESSAGE_ID_MISSING_FROM_core_email_queue'

Solution 2: Quick & Dirty one

Other quick and dirty solution which I have not tried, but you can try on test server first is to

TRUNCATE core_email_queue_recipients;
TRUNCATE core_email_queue;

This should clear all your email queues but will delete the working email queues too.