Reputation: 1591
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
The address is filled in app/config/mail.php:
'from' => array('address' => '[email protected]', 'name' => 'hawle'),
Upvotes: 55
Views: 154973
Reputation: 21
Just fill up mail_from_address in your .env file. Then it will be solved.
[email protected]
Upvotes: 0
Reputation: 31
You May wanna define your mail configs in .env file this way:
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=***USERNAME**
MAIL_PASSWORD=***PASSWORD***
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="${APP_NAME}"
MAIL_FROM_ADDRESS=no-reply@YOURDOMAIN
After making adjustment to your env files make sure to use.
Use
php artisan config:clear
instead of
php artisan config:cache
This helped me out, Hopefully, it'll help you out as well. Cheers!
Upvotes: 2
Reputation: 506
Just in case you are facing this challenge in the deployment phase and getting the same error after trying all the above steps, ensure you do not have the MAIL_FROM_ADDRESS duplicated in the .env file. If you have one commented out, delete that too.
Upvotes: 1
Reputation: 39
I did all the above and still I wasn't getting the expected result. The error instead changed to: Expected response code 250 but got code “530”, with message "530 5.7.1 Authentication required
From here all you need to do is restart the development server by running; php artisan serve
This worked very well for me.
Upvotes: 0
Reputation: 103
I don't understand why, but I already did all above and nothing changed. Did toggle on/off php artisan serve
.
What I did to solve this problem is by doing restart the PC
and it's then running smoothly.
Note:
php artisan serve
still running. And I think this might lead to a bug.Upvotes: 0
Reputation: 201
please check your "MAIL_FROM_ADDRESS" should not be empty. and then use php artisan config:clear
worked for me.
Upvotes: 3
Reputation: 1387
Managed to fix this by doing the following
Goto .env file
Make sure the value for MAIL_FROM_ADDRESS
is set.
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=***USERNAME**
MAIL_PASSWORD=***PASSWORD***
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="${APP_NAME}"
MAIL_FROM_ADDRESS=no-reply@YOURDOMAIN
Upvotes: 9
Reputation: 46
You need to change these defaults with your own values
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
Upvotes: 0
Reputation: 10572
If you are using gmail account, settings are different now. Config .env
:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
[email protected]
You can also ssl encryption and then following settings:
MAIL_ENCRYPTION=ssl
MAIL_PORT=465
And after setting everything run:
php artisan config:cache
You may also need to check on option "Less secure app access" on https://myaccount.google.com/security.
Upvotes: 1
Reputation: 53
go to you .env
file which is located at the root of your folder
Then set your configuration for mail like this if you are also using smpt.mailtrap.io
as MAIL_HOST.
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=******username******
MAIL_PASSWORD=******password******
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
now to set your MAIL_USERNAME
and MAIL_PASSWORD
click here to go to mailtrap
now sign up or login if you already have an account for it.
then click Inbox then select demo inbox there you'll find the integration dropdown then select for Laravel and it will provide you with the username and password required to fulfill you .env
file.
then save the information in your .env
file for you Mail Configuration.
Now the most important part is that you run these two command line in your terminal.
run php artisan serve
again
run php artisan config:clear
Then do your process and check out the mailtrap inbox. for me it worked like this.
Upvotes: 4
Reputation: 302
Make sure MAIL_FROM_ADDRESS in env .file is not null.
[email protected]
the next step you have to use these commands:
php artisan config:cache
php artisan cache:clear
I hope it was useful.
Upvotes: 3
Reputation: 21
In Laravel 7 , your .env file should be like this
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME="your username"
MAIL_PASSWORD="your password"
MAIL_ENCRYPTION=tls
#MAIL_FROM_ADDRESS=null
#MAIL_FROM_NAME="${APP_NAME}"
Make sure these two lines are commentout like this...
#MAIL_FROM_ADDRESS=null
#MAIL_FROM_NAME="${APP_NAME}"
Final step: run these step of command in your terminal to successfully send notification -
php artisan config:cache
php artisan cache:clear
php artisan config:clear
Upvotes: 2
Reputation: 1655
I have tried all the solution here but didn't work until I run this three commands
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Upvotes: 2
Reputation: 1
the problem is the null value of MAIL_FROM_ADDRESS in .env file.
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):
'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'),
]
Upvotes: 0
Reputation: 2644
Don't forgot also to clear config cache ! it was the problem where I was facing !
php artisan config:cache
Upvotes: 1
Reputation: 61
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.
Here are my .env settings:
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}"
Upvotes: 6
Reputation: 397
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
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
php artisan config:cache
Upvotes: 16
Reputation: 51
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!');
...
Upvotes: 3
Reputation: 11
The file: /bootstrap/cache/config.php
The change:
'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',
Upvotes: -2
Reputation: 4170
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
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' => '[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.
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:
mail.php
file is located at /app/config/mail.php
(as OP said). .env
file is located at the root of your project. 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
Upvotes: 100
Reputation: 21
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:
'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.
Upvotes: 2
Reputation: 1462
Make sure you have set the 'from' in app/config/mail.php
'from' => ['address' => '[email protected]', 'name' => 'myname']
It will fix the problem.
Upvotes: 24