multiple mail configurations

后端 未结 7 696
遇见更好的自我
遇见更好的自我 2020-11-28 07:13

I configured laravel\'s mail service with mandrill driver. No problems here!

Now, at certain point of my application, I need to send a mail via gmail.

I did

7条回答
  •  长情又很酷
    2020-11-28 07:39

    You can create a new Swift_Mailer instance and use that:

    // Backup your default mailer
    $backup = Mail::getSwiftMailer();
    
    // Setup your gmail mailer
    $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl');
    $transport->setUsername('your_gmail_username');
    $transport->setPassword('your_gmail_password');
    // Any other mailer configuration stuff needed...
    
    $gmail = new Swift_Mailer($transport);
    
    // Set the mailer as gmail
    Mail::setSwiftMailer($gmail);
    
    // Send your message
    Mail::send();
    
    // Restore your original mailer
    Mail::setSwiftMailer($backup);
    

提交回复
热议问题