在忘记密码的情况下,laravel发送的电子邮件错误如下:
Swift_TransportException in AbstractSmtpTransport.php line 162:
无法发送没有发件人地址的邮件
我已经在.env
和mail.php
设置了我的邮件帐户详细信息。
我的.env:
MAIL_DRIVER=smtp
MAIL_HOST=smtp-mail.outlook.com
MAIL_PORT=587
MAIL_USERNAME=raval_himanshu@live.in
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=tls
我的mail.php是
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp-mail.outlook.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['raval_himanshu@live.in' => null, 'Himanshu Raval' => null],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('raval_himanshu@live.in'),
'sendmail' => '/usr/sbin/sendmail -bs',
];
我也试过了php artisan config:cache
,但之后也出现了同样的错误。
答案 0 :(得分:7)
我在mail.php
'from' => ['raval_himanshu@live.in' => null, 'Himanshu Raval' => null],
应该是
'from' => ['address' => 'raval_himanshu@live.in', 'name' => 'Himanshu Raval'],
答案 1 :(得分:4)
只需尝试以下代码,因为这对我有用 在 .env 文件
中MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=myAPPpassword_Generatedfromhttps://myaccount.google.com/security#signin
MAIL_ENCRYPTION=tls
在 config / mail.php 中我改变了这个
'from' => ['address' => 'myemail@gmail.com', 'name' => 'Admin.com'],//default :'from' => ['address' => null, 'name' => null],
然后运行php artisan config:cache
清除配置缓存并再次使用新配置缓存,我希望可以提供帮助
答案 2 :(得分:0)
您应该在您创建的邮件示例的构建功能中执行此操作
public function build()
{
return $this->from('example@gmail.com')->view('welcome');
}
答案 3 :(得分:0)
.env 更新后,请重启 php artisan(CTRL+C 然后 php artisan serve)