Question

[Solved] Laravel Homestead Swift Cannot send message without a sender address

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

Solution #1:

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

Respondent: Szenis

Solution #2:

Make sure you have set the ‘from’ in app/config/mail.php

'from' => ['address' => '[email protected]', 'name' => 'myname']

It will fix the problem.

Respondent: Ali

Solution #3:

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
Respondent: Ismynr

Solution #4:

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}"
Respondent: Ben Holmen

Solution #5:

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

IlluminateSupportFacadesMail::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!');
...
Respondent: felisleo119

Solution #6:

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.

Respondent: Cristian Cordeiro

Solution #7:

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.

Solution #8:

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
[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.

Respondent: sunnyinho

Solution #9:

Don’t forgot also to clear config cache ! it was the problem where I was facing !

php artisan config:cache
Respondent: Goms

Solution #10:

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

Respondent: Saddan

Solution #11:

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
    
Respondent: AMIT SAHA

Solution #12:

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

Respondent: tarik ben

Solution #13:

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.

Respondent: Jsowa

Solution #14:

You need to change these defaults with your own values

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],
Respondent: Dzmond

Solution #15:

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}"
[email protected] 
Respondent: Anon

Solution #16:

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',
Respondent: Ali Najafi

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy