在laravel 5.2中没有发件人地址的情况下无法发送消息我已经设置了.env和mail.php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34873613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:15:55  来源:igfitidea点击:

Cannot send message without a sender address in laravel 5.2 I have set .env and mail.php both

phplaravellaravel-5.2swiftmailer

提问by Himanshu Raval

In forgot password laravel sends email which gives error like :

在忘记密码时,laravel 会发送电子邮件,其中出现如下错误:

Swift_TransportException in AbstractSmtpTransport.php line 162:

Cannot send message without a sender address

没有发件人地址无法发送邮件

i already have set my mail account details in .envand mail.phpboth.

我已经在.envmail.php两者中设置了我的邮件帐户详细信息。

My .env :

我的 .env :

MAIL_DRIVER=smtp
MAIL_HOST=smtp-mail.outlook.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=tls

and my mail.php is

我的mail.php是

<?php

return [   

'driver' => env('MAIL_DRIVER', 'smtp'),    

'host' => env('MAIL_HOST', 'smtp-mail.outlook.com'),    

'port' => env('MAIL_PORT', 587),  

'from' => ['[email protected]' => 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('[email protected]'),



'sendmail' => '/usr/sbin/sendmail -bs',

];

i have tried php artisan config:cachetoo but after that it gives same error.

我也试过,php artisan config:cache但在那之后它给出了同样的错误。

回答by Himanshu Raval

i have made mistake in mail.php

我犯了错误 mail.php

'from' => ['[email protected]' => null, 'Himanshu Raval' => null],

that should be

那应该是

'from' => ['address' => '[email protected]', 'name' => 'Himanshu Raval'],

回答by I Made Pustikayasa

just try this code below, because this work for me in .envfile

只需尝试下面的代码,因为这在.env文件中对我有用

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=myAPPpassword_Generatedfromhttps://myaccount.google.com/security#signin
MAIL_ENCRYPTION=tls

in config/mail.phpi change like this

config/mail.php我像这样改变

 'from' => ['address' => '[email protected]', 'name' => 'Admin.com'],//default :'from' => ['address' => null, 'name' => null],

then run the php artisan config:cacheto clear configurations cache and cache again with new configurations, i hope can help

然后运行php artisan config:cache以清除配置缓存并使用新配置再次缓存,我希望可以提供帮助