当我尝试发送密码重置邮件时,我在 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' => 'myusername@gmail.com', 'name' => 'hawle'),
最佳答案
在您的.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' => 'myusername@gmail.com', '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
关于php - Laravel Homestead Swift 无法在没有发件人地址的情况下发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31871806/