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! 🙂