当我试图发送密码重置邮件时,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

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

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 is a service for testing SMTP. It does not really send emails.

As Viktorminator mentioned: Take into consideration creating app passwords and not using your usual pass for this needs. Link for creating passwords myaccount.google.com/apppasswords

Laravel相关问答推荐

我是否需要/是否可以从控制器运行LARLAVEL备份?

Laravel 9 上的数组差异助手

Laravel:在失败时处理 findOrFail()

Laravel + Plupload 上传到 S3 响应以进行预检无效 - CORS

如何在 Laravel Passport 中获取刷新令牌?

如何为路由 laravel 5 使用OR中间件

Laravel 5文件夹 struct 中的文件保存在哪里?

如何在 NetBeans 中添加带有点 (blade.php) 的自定义文件扩展名?

路由中间的可选参数

Laravel Session 总是改变 Laravel 5.4 中的每个刷新/请求

Laravel:`loadMissing` 函数的目的是什么?

Laravel 4,如何测试复选框是否被选中?

Laravel:每当我返回一个模型时,总是返回一个与它的关系

Laravel 5.1 重命名项目

如何更改默认 Laravel Auth 登录视图

Composer RuntimeException - 无法加载软件包 mews/purifier

配置和测试 Laravel 任务调度

如何在 laravel eloquent 中保存布尔值

Eloquent的关系 - attach附加(但不保存)到 Has Many

Laravel or where