我需要从多封邮件中发送邮件例如[email protected]
,[email protected]
在.env文件中,我输入了默认设置
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
我使用markdown
电子邮件
public function build()
{
return $this->markdown('emails.users.resetpassword',[
'url' => url(config('app.url').route('password.reset', $this->token, false)),
'user' => $this->notifiable,
]);
}
这很好用
我尝试即时更改发件人邮件
Config::set('mail.encryption','ssl');
Config::set('mail.host','smtps.example.com');
Config::set('mail.port','465');
Config::set('mail.username','[email protected]');
Config::set('mail.password','password');
Config::set('mail.from', ['address' => '[email protected]' , 'name' => 'Your Name here']);
但它仍然从主帐户发送!
如何更改发件人邮件?在此先感谢
您可以在运行时覆盖配置
use \Swift_Mailer;
use \Swift_SmtpTransport as SmtpTransport;
$transport = (new SmtpTransport(config('mail.host_other'), config('mail.port_other'), config('mail.encryption_other')))->setUsername(config('mail.username_other'))->setPassword(config('mail.password_other'));
$mailer = new Swift_Mailer($transport);
Mail::setSwiftMailer($mailer);
Mail::send(...);
在您的mail.php配置文件中,添加
<?php
return [
....
....
'host_other' => env('HOST_OTHER'),
'port_other' => env('PORT_OTHER'),
'encryption_other' => env('MAIL_ENCRYPTION_OTHER'),
'username_other' => env('MAIL_USERNAME_OTHER'),
'password_other' => env('MAIL_PASSWORD_OTHER'),
....
....
]