我使用 mandrill 驱动程序配置了 laravel 的邮件服务。这里没有问题!
现在,在我申请的某个时刻,我需要通过 gmail 发送邮件。
我做了类似的事情:
// backup current mail configs
$backup = Config::get('mail');
// rewrite mail configs to gmail stmp
$new_configs = array(
'driver' => 'smtp',
// ... other configs here
);
Config::set('mail', $new_configs);
// send the email
Mail::send(...
// restore configs
Config::set('mail', $backup);
这是行不通的,laravel 总是使用 mandrill 配置。看起来他在脚本启动时启动了邮件服务,并忽略了您在执行过程中所做的任何事情。
如何在执行过程中更改邮件服务配置/行为?
您可以创建一个新的Swift_Mailer
实例并使用它:
// 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)