Magento 1.9 Fix for Sending Double Emails or Sending Email to Wrong Recipients

by | 2 Jul 2017 | Database, Magento, MySQL, Open Source, PHP, PhpMyAdmin, Technology | 0 comments

As we know, Magento uses a cron job system to send out email from core_email_queue table. There is an additional table called core_email_queue_recipients, which as the name states, will store all recipients for emails there. But these records do not get removed at times and that is usually why you will get the issue of Magento sending double emails or sending email to wrong recipients.

Follow the following steps to have this issue fixed.

1. Clean up core_email_queue_recipients table

Executing the two SQL statements below will remove any orphan email recipient records so that Magento will not send double emails or send email to wrong receipents.

DELETE FROM core_email_queue_recipients WHERE message_id NOT IN (SELECT message_id FROM core_email_queue);

DELETE FROM core_email_queue_recipients WHERE recipient_id < (SELECT recipient_id FROM (SELECT recipient_id FROM core_email_queue_recipients ORDER BY message_id ASC, recipient_id DESC LIMIT 1) AS r);

2. Alter core_email_queue_recipients

Altering core_email_queue_recipients table to attach a foreign key to every recipient record so that it will get deleted when an email is done sending.

ALTER TABLE core_email_queue_recipients ADD FOREIGN KEY(message_id) REFERENCES core_email_queue(message_id) ON DELETE CASCADE;

 

You are welcome! 🙂

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Posts

APCCentOSFedoraLinuxOSPHPProgrammingServerTechnology
Install APC (Alternative PHP Cache) in CentOS 5/6/7 and Fedora 20/21

Install APC (Alternative PHP Cache) in CentOS 5/6/7 and Fedora 20/21

APC (Alternative PHP Cache) is a free and open source tool to cache PHP codes. 1. Install Dependency Packages for APC yum install php-pear php-devel httpd-devel pcre-devel gcc make -y 2. Install APC using PECL (PHP Extension Community Library) pecl install apc...