Laravel Homestead Swift无法在没有发件人地址的情况下发送消息
当我尝试发送密码重置邮件时,在Laravel 5.1 Homestead中的库存电子邮件设置出现此错误.
I get this error with stock email settings in Laravel 5.1 Homestead when I try to send a password reset mail.
Swift_TransportException in AbstractSmtpTransport.php line 162:Cannot send message without a sender address
地址填写在app/config/mail.php中:
The address is filled in app/config/mail.php:
'from' => array('address' => 'myusername@gmail.com', 'name' => 'hawle'),
在您的.env
文件中,您需要设置电子邮件帐户的电子邮件地址和密码.您还需要设置要使用的邮件服务器的主机和端口.
In your .env
file you will need to set the email address and password of your email account. You also need to set the host and port of the mail server you are using.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=25
MAIL_USERNAME= ***USER NAME***
MAIL_PASSWORD= ***PASSWORD***
MAIL_ENCRYPTION=tls
或确保您的mail.php
文件中的所有内容均完整(请参见下面的注释).
Or make sure that everything is complete in your mail.php
file (see note below).
'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
文件,因为您很可能在生产环境中使用不同的配置.
Note: It's better to use the .env
file, as you most likely will have a different configuration in your production environment.
如果一切都完成了,但仍然无法正常工作,则可能是正在缓存.您可以使用以下命令清除配置缓存:
If everything is completed and it still doesn't work, it might be caching. You can clear the config cache with this:
php artisan config:cache
也请注意:
- 端口465用于Gmail.如果不起作用,则可以使用25.
-
mail.php
文件位于/app/config/mail.php
(如OP所述). -
.env
文件位于项目的根目录. - Mailtrap.io是用于测试SMTP的服务.它实际上并不发送电子邮件.
- Port 465 is for Gmail. If it does not work, you can use 25.
- The
mail.php
file is located at/app/config/mail.php
(as OP said). - The
.env
file is located at the root of your project. - Mailtrap.io is a service for testing SMTP. It does not really send emails.
正如Viktorminator所述: 请考虑创建应用程序密码,并且不使用常规密码来满足此需求.用于创建密码的链接 myaccount.google.com/apppasswords