Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincej's avatar
Level 15

Problem: "Can Not Send Message Without a Sender Address"

I have tried everything. Since upgrading from 4.2 to 5.1 my previous config/mail settings refuse to work with neither Mandrill nor Gmail, both giving the same error message above. However they all worked fine under 4.2.

So, I have Googled extensively, watched Jeffrey's tutorial, checked the user docs, and double, double checked all my settings 20x. I have tried hard coding the settings as well as using the env variables. I have also restarted the server as well as did a clear-cache several times. I can not see it. So far everything gives the same error message. It look like a lot of people have had this problem coming up from 4.2 to 5.1.

<?php

return [

   
    'driver' => 'smtp',                 
    'host' => 'smtp.gmail.com',         
    'port' => 587,                  
    'from' => ['address' => 'vincej1657@gmail.com', 'name' => 'Admin'],
    'encryption' => 'tls',
    'username' => 'vincej1657@gmail.com',   
    'password' => 'My_password',        
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

Many thanks for all your ideas !

0 likes
54 replies
lindstrom's avatar

Your config looks good. You might need to explicitly set the from in your mailer or wherever your constructing the message. Could we see that?

vincej's avatar
Level 15

@jimmck thanks for your suggestion - it made no difference.

@lindstrom Thank for your reply. Here is what I think you asked for. I have done a dd() on $email and it comes out with the required email.

public function store(Request $request)
    {

        $this->validate($request,
            [
                'first_name' => 'required',
                'last_name' => 'required',
                'cellphone_number' => 'required',
                'email'=>'required',
                'square_rate' => 'required|numeric',
                'hour_rate' => 'required_if:square_rate, 0.00',
            ]);

        Contractor::create(Input::all());

        $email = $request->email;
       
        Mail::send('emails.new_contractor', ['email' => $email], function ($message) use ($email) {
            $message->to($email)->subject('Welcome to AuburnTree');
        }
        );

        Flash::success('New Contractor Created');
        return redirect('labour/contractors/show');
    }

vincej's avatar
Level 15

@jimmck

I think I show you above, earlier in this post.

I have made a change to my mailer and I now have a different error message !

I added $message->sender('noreply@test.com');

 Mail::send('emails.new_contractor', ['email' => $email],

            function ($message) use ($email) {
            $message->sender('noreply@test.com');
            $message->to($email)->subject('Welcome to AuburnTree');
            }
        );

The previous error message is now gone, however, now I get the error:

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
"
jimmck's avatar

@vincej Can you please post your mail.php file from app/config exactly as it is. Thats all. The other error is timeout. Humor me :)

vincej's avatar
Level 15

@jimmck

Heah Jim, Thanks for all this ! Here you go - I have since changed my app/config to use the .env rather than hard coded,

.env

APP_ENV=local
APP_DEBUG=true
APP_KEY=BicAzhxnDrsYzcbx6bAwGJ5KF7oBDDQM

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync


MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=vincej16757@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null

config.mail.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "ses", "log"
    |
    */

    'driver' => env('MAIL_DRIVER'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Mailgun mail service which will provide reliable deliveries.
    |
    */

    'host' => env('MAIL_HOST'),

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

    /*
    |--------------------------------------------------------------------------
    | 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' => 'vincej1657@gmail.com', 'name' => 'Admin'],

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

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Username
    |--------------------------------------------------------------------------
    |
    | If your SMTP server requires a username for authentication, you should
    | set it here. This will get used to authenticate with your server on
    | connection. You may also set the "password" value below this one.
    |
    */

    'username' => env('MAIL_USERNAME'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Password
    |--------------------------------------------------------------------------
    |
    | Here you may set the password required by your SMTP server to send out
    | messages from your application. This will be given to the server on
    | connection so that the application will be able to send messages.
    |
    */

    'password' => env('MAIL_PASSWORD'),

    /*
    |--------------------------------------------------------------------------
    | Sendmail System Path
    |--------------------------------------------------------------------------
    |
    | When using the "sendmail" driver to send e-mails, we will need to know
    | the path to where Sendmail lives on this server. A default path has
    | been provided here, which will work well on most of your systems.
    |
    */

    'sendmail' => '/usr/sbin/sendmail -bs',

    /*
    |--------------------------------------------------------------------------
    | Mail "Pretend"
    |--------------------------------------------------------------------------
    |
    | When this option is enabled, e-mail will not actually be sent over the
    | web and will instead be written to your application's logs files so
    | you may inspect the message. This is great for local development.
    |
    */

    'pretend' => false,

];

vincej's avatar
Level 15

@jimmck

I recently did a full reinstall of everything, following a SSD install. Do I have to enable smtp in Apache or PHP for this work ?

bashy's avatar

You don't need to install or enable SMTP. It uses SwiftMailer?

The error is weird though, it just means it needs a sender being set in the from address... Have you tried it with null? I'm pretty sure Gmail doesn't allow it to be changed anyway. Try with TLS as encryption as well.

jimmck's avatar

@vincej I tried tracing the code, its has too many 3 line functions. The expected type is off, or its looking where it does not. You are setting the from manually? But yeah the Swiftmailer code send the from, actually the whole header on a ride.

Why does first mail config listing look different from the one you just sent? You I have had fun with AWS config files because I did not vendor:publish, or did not install in FDA recomended order :)

vincej's avatar
Level 15

@jimmck Thank for all your help !!

The second config listing looks different as in the intervening time I am trying everything I can. Mandrill, then Gmail ... I am looking at everything I can from Stackoverflow to Laracasts Forums. Sheesh there are a lot of people who have the same / similar problems with Mail in Laravel.

As for the rest of your post, please forgive me, but I don't really understand what you are saying to me. :o)

vincej's avatar
Level 15

@jimmck Just had a thought - I still am getting a raft of IDE "warnings" eg $message->sender() gives "method sender not found"

could this be giving a problem ?

jimmck's avatar

@vincej Well it could be not found. But the IDE has trouble sometimes resolving the symbols because of the dynamic nature of PHP. Thats what the IDE Helper tries to fix. Like I was saying about reading the code. The Mailer code implements Abstract classes so $message is a Swift Mailer object. I was working on a bug, but got it working when I saw your plight. Anyway first thing is get your config files in order so you are not chasing gremlins. Like I said, that has plagued me more times than not. I will try a mail example with gmail and see what I can.

lindstrom's avatar

@vincej do you have 2-step verification turned on for your Gmail account? If so, you have to use an App Password--not your regular password. I just tested this with my Gmail account both ways. It worked fine with the App Password.Go to https://myaccount.google.com the Sign in & Security > Signing into Google. Last option on right. Use the 16 digit password and let us know how you make out.

vincej's avatar
Level 15

@lindstrom

Thanks for your help - I had not thought of this. I did not have 2 step verification on, however I did set it up, got the password and entered it in the .env file. However I still am getting a "530" error, ie authentication failure. So I also changed the port from 587 to 465 and added TLS as per digital ocean instructions, also to no avail.

lindstrom's avatar

@vincej I just noticed something in your config. You need to use your full gmail address. vincej16757@gmail.com for your user name. Also, no spaces in your app key.

vincej's avatar
Level 15

@lindstrom

here are my env variables specific to mail:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com                // tried with smtp.googlemail.com as well.  
MAIL_PORT=587                           // tried with 25 and 465 as well
MAIL_USERNAME=vincej1657@gmail.com
MAIL_PASSWORD= MyAppKey from google 
MAIL_ENCRYPTION=tls                     //  I have tried with null as well

my config mail file has no values in it other than the .env constants and the "from" address

jimmck's avatar

@vincej Your password is your Google mail password. Your APP_KEY is different.

vincej's avatar
Level 15

@jimmck @lindstrom

Ok - tried it again with my standard password and again authentication error 530 5.7.1. Surely I need to turn 2 step verification off if I am not to use the app_key ?? No ?

jimmck's avatar

Yes. Unless you got an APP_KEY. Does Google support this w/o an APP_KEY? Everything I use requires me to get one.

vincej's avatar
Level 15

@jimmck

ok - I have an app_key, if I don't put it is my pw as suggested by Lindstrom, then where do I put it ?

vincej's avatar
Level 15

@jimmck @lindstrom

ok - found the spot in the .env at the top for the app_key. It still gives me an authentication error. ugh.

lindstrom's avatar

@vincej

You use your Google App key for MAIL_PASSWORD in your .env. Your APP_KEY is for Laravel. Remeber to update mail.php to use your environment variables:

EDIT: MAIL_USERNAME needs to be your full gmail address. It isn't in the last .env you posted above.

vincej's avatar
Level 15

@lindstrom

ok this might be my problem:

Remember to update mail.php to use your environment variables

How do I do this ? My mail.php is pure vanila.

return [
    'driver' =>  env('MAIL_DRIVER'),
    'host' => env('MAIL_HOST'),
    'port' => env('MAIL_PORT'),
    'from' => ['address' => 'vincej1657@gmail.com', 'name' => 'Admin'],
    'encryption' => env('MAIL_ENCRYPTION'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

vincej's avatar
Level 15

@lindstrom

Well, I'm stuck .. I just don't get it. I love Laravel and would never go back to Codeigniter where I came from, but sometimes I do think things are harder than they need to be all of which can cost a lot of time.

vincej's avatar
Level 15

@lindstrom @jimmck

can we agree on one thing: where the google app_key goes ? Lindstrom says it goes on MAiL_PASSWORD. Jim says it does not.

where should I put it ?

Next

Please or to participate in this conversation.