php Laravel Homestead Swift 无法在没有发件人地址的情况下发送消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31871806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Homestead Swift Cannot send message without a sender address
提问by Gergely Havlicsek
I get this error with stock email settings in Laravel 5.1 Homestead when I try to send a password reset mail.
当我尝试发送密码重置邮件时,我在 Laravel 5.1 Homestead 中的股票电子邮件设置中收到此错误。
Swift_TransportException in AbstractSmtpTransport.php line 162:Cannot send message without a sender address
The address is filled in app/config/mail.php:
地址填写在app/config/mail.php中:
'from' => array('address' => '[email protected]', 'name' => 'hawle'),
回答by Szenis
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.
在您的.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).
或者确保文件中的所有内容都已完成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'),
Note: It's better to use the .env
file, as you most likely will have a different configuration in your production environment.
注意:最好使用该.env
文件,因为您的生产环境中很可能会有不同的配置。
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
Also note:
另请注意:
- 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.
- 端口 465 用于 Gmail。如果它不起作用,您可以使用25。
- 该
mail.php
文件位于/app/config/mail.php
(如OP所说)。 - 该
.env
文件位于项目的根目录下。 - Mailtrap.io 是用于测试 SMTP 的服务。它并没有真正发送电子邮件。
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
正如 Viktorminator 提到的:考虑创建应用程序密码而不是使用您通常的通行证来满足此需求。用于创建密码的链接myaccount.google.com/apppasswords
回答by Ali
Make sure you have set the 'from' in app/config/mail.php
确保您已在 app/config/mail.php 中设置了“发件人”
'from' => ['address' => '[email protected]', 'name' => 'myname']
It will fix the problem.
它将解决问题。
回答by Ismynr
Maybe someone is using laravel 6
Its problem is "Cannot send message without a sender address" so there is no email address to send the email in .env
file
也许有人正在使用 laravel 6
它的问题是“没有发件人地址就无法发送消息”所以没有电子邮件地址可以在.env
文件中发送电子邮件
Just add sender email address
只需添加发件人电子邮件地址
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=null
[email protected] **here**
MAIL_FROM_NAME="${APP_NAME}"
I didn't change anything in the mail.php file, its work for me in laravel 6, after that run
我没有更改 mail.php 文件中的任何内容,在运行之后,它在 Laravel 6 中对我有用
php artisan config:cache
回答by Cristian Cordeiro
If you don't have access to the .env file, you can add default values to those env calls on app/config/mail.php, like this:
如果您无权访问 .env 文件,则可以在 app/config/mail.php 上为这些 env 调用添加默认值,如下所示:
'from' => ['address' => env('MAIL_FROM_EMAIL','[email protected]'), 'name' => env('MAIL_FROM_NAME','SpongeBob')],
This approach will try to get the data from the .env file, if there's nothing there, it'll default to whatever you set.
这种方法将尝试从 .env 文件中获取数据,如果那里没有任何内容,它将默认为您设置的任何内容。
回答by felisleo119
error was still occure. after settings and run commands
错误仍然发生。设置和运行命令后
php artisan view:clear;
php artisan config:cache;
php artisan cache:clear;
php artisan route:cache;
check the code
检查代码
\Illuminate\Support\Facades\Mail::send('layouts.mail', [ 'content' => 'testmail'], function ($m) use ($msg2){
$m->from('[email protected]', 'ABC');
// this line was env('MAIL_FROM_ADDRESS') ; cant read from .env
$m->to('[email protected]', 'XYZ')->subject('TestMailSubject!');
...
回答by Ben Holmen
I just solved this in Laravel 7.9. I'm using mailtrap.io and I believe the issue was a missing MAIL_ENCRYPTION=tls
variable. This variable is not present in the mailtrap.io sample config OR the .env.example file.
我刚刚在 Laravel 7.9 中解决了这个问题。我正在使用 mailtrap.io,我相信问题是缺少MAIL_ENCRYPTION=tls
变量。此变量不存在于 mailtrap.io 示例配置或 .env.example 文件中。
Here are my .env settings:
这是我的 .env 设置:
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=[found in mailtrap settings]
MAIL_PASSWORD=[found in mailtrap settings]
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
回答by Goms
Don't forgot also to clear config cache ! it was the problem where I was facing !
不要忘记清除配置缓存!这是我面临的问题!
php artisan config:cache
回答by tarik ben
the problem is the null value of MAIL_FROM_ADDRESS in .env file.
问题是 .env 文件中 MAIL_FROM_ADDRESS 的空值。
solutions 1: change the value of the MAIL_FROM_ADRESS to match your email address(don t forget to rerun your server). solution 2: keep the .env file as it was but you need to change mail.php(app/config/mail.php):
解决方案 1:更改 MAIL_FROM_ADRESS 的值以匹配您的电子邮件地址(不要忘记重新运行您的服务器)。解决方案 2:保持 .env 文件原样,但您需要更改 mail.php(app/config/mail.php):
from these:
从这些:
'from' => [
'address' => env('MAIL_FROM_ADDRESS','[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
]
to:
到:
'from' => [
'address' => '[email protected]',
'name' => env('MAIL_FROM_NAME', 'Example'),
]
回答by Sky7ure
回答by Ali Najafi
The file: /bootstrap/cache/config.php
The change:
文件:/bootstrap/cache/config.php
更改:
'mail' => array(
'driver' => 'smtp',
'host' => 'mail.yourserversiteemail.com',
'port' => '25',
'from' =>
array(
'address' => '[email protected]',
'name' => 'sd',
),
'encryption' => 'tls',
'username' => 'yourUsername',
'password' => 'yourPass',
'sendmail' => '/usr/sbin/sendmail -bs',