Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel mail is sending email twice when added bcc

I am trying to send email with Bcc, but I have noticed that SwiftMailer is sending emails twice (one with Bcc and the other without it), and I removed bcc it's working fine without duplicated mails.

mailController.php

class mailController extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */      
    public function __construct()
    {
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {   
        return $this->from('[email protected]', 'test')
        ->view('portal.confirmation')
        ->subject('test Email')
        ->bcc('[email protected]','wahdan');
    }
}

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525

Update

This issue happen only in local environment ,but in production it's working perfect without any duplicated emails.

like image 941
wahdan Avatar asked Jan 08 '18 13:01

wahdan


1 Answers

If you BCC an email and send it through mailtrap.io, you will receive two copies of the email in your mailbox. If there are two BCCs, you will receive three copies, etc. The emails will look identical (including the "To:").

This behavior is specific to mailtrap.io, not Laravel (i.e., it is not on the sending side).

If the number of duplicate emails is the same as the number of BCCs plus the original, I think you can be confident that is the reason.

This answer assumes that you are using mailtrap.io as your SMTP server locally, but not in production.

like image 77
SCruz Avatar answered Oct 03 '22 15:10

SCruz