laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.7k stars 11.06k forks source link

Universal To using CC and BCC, ends up with 3 mails #20075

Closed empresarrollo closed 7 years ago

empresarrollo commented 7 years ago

Description:

When using "Universal TO" in config/mail.php:

    'to' => [
        'address' => 'myuser@mymail.com',
        'name' => 'Testing Dude'
    ],

and using MAIL_DRIVER=log, or smtp, or sparkpost, Laravel put your "universal to" also on the CC and BCC fields of the email. Then you end up with 3 copies of the same mail.

Steps To Reproduce:

  1. php artisan make:notification InvoicePaid --markdown=mail.invoice.paid
  2. create view for mail.invoice.paid
  3. modifiy toMail() in InvoicePaid: return (new MailMessage)->subject('Invoice Paid')->markdown('mail.invoice.paid');
  4. $user = App\User->create(...........)
  5. $user->notify((new InvoicePaid($invoice));

using MAIL_DRIVER=log you would see the folowing in laravel.log:

[2017-07-14 17:31:12] local.DEBUG: Message-ID: <d4764c5f1436236c5460ae97b0bbb686@myapp.dev>
Date: Fri, 14 Jul 2017 17:31:12 -0300
Subject: Invoice Paid
From: MyApp <noresponse@email.myapp.com>
To: Testing Dude <myuser@mymail.com>
Cc: Testing Dude <myuser@mymail.com>
Bcc: Testing Dude <myuser@mymail.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;

with log everything is OK, but if you use smtp or sparkpost to test the emails you and up with triple the mails.

Douglasdc3 commented 7 years ago

Setting a global to in your config will override any other mail address already set before. According to the code you should only use this for local development.

        // If a global "to" address has been set, we will set that address on the mail
        // message. This is primarily useful during local development in which each
        // message should be delivered into a single mail address for inspection.
        if (isset($this->to['address'])) {
            $this->setGlobalTo($message);
        }
devcircus commented 7 years ago

16705

empresarrollo commented 7 years ago

Setting a global to in your config will override any other mail address already set before. According to the code you should only use this for local development.

Yeah, I'm using for development, and testing that sparkpost works ok. But setting to also put that address in CC and BCC (although I'm not using that).

themsaid commented 7 years ago

Check https://github.com/laravel/framework/pull/16705