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

末鹿安然 提交于 2019-12-10 12:25:55

问题


In forgot password laravel sends email which gives error like :

Swift_TransportException in AbstractSmtpTransport.php line 162:

Cannot send message without a sender address

i already have set my mail account details in .env and mail.php both.

My .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

and my mail.php is

<?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',

];

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


回答1:


i have made mistake in mail.php

'from' => ['raval_himanshu@live.in' => null, 'Himanshu Raval' => null],

that should be

'from' => ['address' => 'raval_himanshu@live.in', 'name' => 'Himanshu Raval'],



回答2:


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

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

in config/mail.php i change like this

 'from' => ['address' => 'myemail@gmail.com', 'name' => 'Admin.com'],//default :'from' => ['address' => null, 'name' => null],

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



来源:https://stackoverflow.com/questions/34873613/cannot-send-message-without-a-sender-address-in-laravel-5-2-i-have-set-env-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!