Laravel Homestead Swift Cannot send message without a sender address
PhpLaravelLaravel 5.1Php Problem Overview
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'),
Php Solutions
Solution 1 - Php
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:
- 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.
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
Solution 2 - Php
Make sure you have set the 'from' in app/config/mail.php
'from' => ['address' => '[email protected]', 'name' => 'myname']
It will fix the problem.
Solution 3 - Php
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
MAIL_FROM_ADDRESS[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
Solution 4 - Php
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
Solution 5 - Php
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
MAIL_FROM_ADDRESS[email protected]
MAIL_FROM_NAME="${APP_NAME}"
Solution 6 - Php
LARAVEL 7 *cannot send message without a sender address *
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
MAIL_FROM_ADDRESS[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.
Solution 7 - Php
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!');
...
Solution 8 - Php
Make sure MAIL_FROM_ADDRESS in env .file is not null.
MAIL_FROM_ADDRESS[email protected]
the next step you have to use these commands:
php artisan config:cache
php artisan cache:clear
I hope it was useful.
Solution 9 - Php
please check your "MAIL_FROM_ADDRESS" should not be empty. and then use php artisan config:clear
worked for me.
Solution 10 - Php
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.
Solution 11 - Php
Don't forgot also to clear config cache ! it was the problem where I was facing !
php artisan config:cache
Solution 12 - Php
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
Solution 13 - Php
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
Solution 14 - Php
If you are using gmail account, settings are different now. Config .env
:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS[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.
Solution 15 - Php
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.
Solution 16 - Php
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 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'),
]
Solution 17 - Php
You need to change these defaults with your own values
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
Solution 18 - Php
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:
- I was using Ubuntu OS.
- Sometime my PC sleep while
php artisan serve
still running. And I think this might lead to a bug.
Solution 19 - Php
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.
Solution 20 - Php
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',