Laravel Homestead Swift无法在没有发件人地址的情况下发送消息

问题描述 投票:20回答:6

当我尝试发送密码重置邮件时,我在Laravel 5.1 Homestead中的库存电子邮件设置出现此错误。

Swift_TransportException in AbstractSmtpTransport.php line 162:Cannot send message without a sender address

地址填写在app / config / mail.php中:

'from' => array('address' => '[email protected]', 'name' => 'hawle'),
php laravel laravel-5.1
6个回答
42
投票

.env文件中,您需要设置电子邮件帐户的电子邮件地址和密码。您还需要设置要使用的邮件服务器的主机和端口。

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=25
MAIL_USERNAME= ***USER NAME***
MAIL_PASSWORD= ***PASSWORD***
MAIL_ENCRYPTION=tls

或确保mail.php文件中的所有内容都完整(请参见下面的注释)。

'host' => env('MAIL_HOST', 'smtp.gmail.com'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 25),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' => '[email protected]', 'name' => 'hawle'],
/*
|--------------------------------------------------------------------------
| 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'),

注意:最好使用.env文件,因为您的生产环境中很可能会有不同的配置。

如果一切都完成了,但仍然无法正常工作,则可能是正在缓存。您可以使用以下命令清除配置缓存:

php artisan config:cache

也请注意:

  • 端口465用于Gmail。如果不起作用,则可以使用25。
  • mail.php文件位于/app/config/mail.php(如OP所述)。
  • .env文件位于项目的根目录。
  • Mailtrap.io是用于测试SMTP的服务。它实际上并不发送电子邮件。
  • 正如Viktorminator所述:

请考虑创建应用程序密码,而不是为此使用常规密码。用于创建密码的链接myaccount.google.com/apppasswords

15
投票

确保已在app / config / mail.php中设置了'from'


2
投票

如果您无权访问.env文件,则可以向app / config / mail.php上的那些env调用添加默认值,如下所示:


0
投票

仍然发生错误。设置并运行命令后


0
投票

为了使Mailtrap在我的情况下起作用,我必须在Laravel 6+上为MAIL_FROM_ADDRESS环境变量提供一个值,而不是保持它为null


-1
投票

文件:/bootstrap/cache/config.php更改:

© www.soinside.com 2019 - 2024. All rights reserved.