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

vincej's avatar
Level 15

@bashy

Thanks for the link. I have had a good look at it and I can not see anything here that has not been tried several times. I think the article is a little out of data as there is no obvious panel with "Allow less secure apps" within gmail set up.

Anyway, I have turned off 2 step authorisation as it is not obvious where the google APP_KEY goes and the link suggests that you don't need high security to send mail.

Bit of a bummer as after 2 days of working on this with some of the best brains on the forum, I still can not get L5 to send emails. Soldier on .. we do this for the big bucks right :o)

cheers !

jimmck's avatar

@vincej, Hi Sorry about your nitemare. Here is my mail.php in app/config

<?php
return array (
  'driver' => 'smtp',
  'host' => 'smtp.gmail.com',
  'port' => 587,
  'from' => array ('address' => 'me@gmail.com', 'name' => 'Jim'),
  'encryption' => 'tls',
  'username' => 'me@gmail.com',
  'password' => 'password',
  'sendmail' => '/usr/sbin/sendmail -bs',
  'pretend' => false,
);

And here is the little code snippet I stuck inside a controller. Note I used Mail::raw to send the mail. I don't want to be bothered with views. I want to send mail dammit :) !!!!

        Mail::raw("Testing", function ($message) {
            $message->to('me@gmail.com', 'Jim')
              ->subject('LaravelGMail App!');
        });

The result...

LaravelGMail App!
Inbox
x 

Jim <...@gmail.com>
8:04 PM (6 minutes ago)

to me 
Testing

Note I had to turn on the 'Allow Less Secure Apps Button from the My Account Page on Goggle.

Of course you would only do this for testing as using your personal GMAIL account would be not good.

Hope This Helps get you back on the Road. I am back to some VueJS fun !!!!

Jim

P.S. Make sure your openssl extension is loaded. do a php -m from a console...

lindstrom's avatar

@vincej You use your Google App password for the MAIL_PASSWORD environment variable. It should look something like this (note, not a real app password):

MAIL_DRIVER=smtp
MAIL_PRETEND=false
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=vincej1657@gmail.com
MAIL_PASSWORD=yqecwojfderotvaxp
MAIL_ENCRYPTION=tls

I'm with @bashy at this point. Try to set up a basic test such as the one in the post he referenced. As I noted previously, while I typically use Mandrill, I was able to test this on Homestead locally successfully with the same configuration you have posted. I'm convinced you are close and it's just some minor config issue (e.g. like a space after the = in MAIL_PASSWORD).

@bashy Could this be line endings? CRLF instead of LF? I'd check that too..

jimmck's avatar

@lindstrom @vincej The example I provide right above works just fine. Vince use your GMAIl email address and password to login.

bashy's avatar

@ all -

I would use mailtrap.io (free account) and test the email sending to make sure that that is working. Mailtrap is just a service to catch all the emails you send out so you can view them.

vincej's avatar
Level 15

@jimmck @lindstrom @bashy

First of all thank you all for helping out in such a generous way. I apologise that this has taken as long as it has.

I have done some rudimentary testing, and I believe that the source of my problem is that L5 is just not reading my config/mail.php file. Why ??

  1. Because if I do a dd('hello') at the top of the mail file it does not render it.
  2. If I omit my controller and place Mail::send() in a Route with a closure I get the same error message as when I place it in a controller, namely:

Test Route:

Route::get('mail', function () {
    Mail::send('emails.new_contractor',  [ ],  function($message){
        $message->to('vincej1657@gmail.com')->subject('Test Email');
    });
});

Resulting error message:

 Swift_TransportException in AbstractSmtpTransport.php line 162: Cannot send message without a sender address

Ie it is not reading the sender value from mail.php

If I add to my closure the following line, I eliminate the sender error message:

 $message->sender('vincej1657@gmail.com');

However, the inclusion of this statement simply creates the old favorite error message telling me that L5 / Swift does not have a password. That is to say, it is not reading the mail.php file where my pw is:

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required

My conclusion is that somewhere, somehow L5 is not reading the mail.php file with or without .env constants

Any ideas what might be causing this ? As I have said before, I recently upgraded from 4.2 to 5.1

As always many thanks !

jimmck's avatar

@vince, Configure your mail.php and use the Mail:raw example in my previous post. It just sends an email through the interface. At a minimum you will get email from Google regarding access to your gmail. This will clarify once and for all that you can send emails. Just find a working controller and stick the raw example in and change the sender.

vincej's avatar
Level 15

@jimmck thanks Jim - I didn't see your post till now, my username is vincej. You used vince

anyway, I did try your Mail::raw example this morning, which I should have told you about. I tried it again just now, and I get the usual error message:

Swift_TransportException in AbstractSmtpTransport.php line 162: Cannot send message without a sender address
lindstrom's avatar

@vincej

First, let's try:

composer dump-autoload

Next, add this to routes.php and visit /mail-config - it will read what Laravel has for your mail variables. Change them in .env and mail.php to see if they are being read properly--particularly 'from' as defined in mail.php.

get('/mail-config',  function() {
    return config('mail');
});

If it looks good, run the raw test you set up again. Grasping at straws just like you at this point, but I think everyone has too much invested to not see you get this solved and find out the root cause.

vincej's avatar
Level 15

@jimmck @lindstrom @bashy

Great News - I have it working ! Last night after 3 days of battling with it, I decided that I would just reinstall my whole L5 and app. Lindstrom - your return config('mail) also helped greatly as I could see exactly what what being passed. I have smtp.gmail working as well as Mandrill. I will stick with Mandrill.

I don't know what fixed things, it will always remain a mystery. However what is not a mystery is all three of your generous and patient contributions. For that I am forever grateful. In Comparison to CodeIgniter, Laravel is a jet fighter. The docs are improving greatly however without people like you guys, people like me would have conceded defeated a long time ago.

The word Thank You is not enough, but that is all I have got.

Cheers Vince !

bashy's avatar

Glad you got it sorted! Very strange issue though.

lindstrom's avatar

@vincej AWESOME!!! I was hesitant to suggest a clean install but that really was your only option. Definitely an odd ball case and glad I could help in some small way. Cheers!

vincej's avatar
Level 15

@lindstrom with a name like Lindstrom, my guess is you are somewhere in Scandinavia ... am I right ?

jimmck's avatar

@vincej Glad to hear you are working. Did you do anything after the install? I literally took mail.php ,put in my gmail creds, read the doc saw Email:: and fired one off after relaxing my gmail setting in the gmail control panel. I am always trying stuff out. I have 10 versions of my composer file. I will not hesitate to noodle with Laravel code to see what its doing. But it takes a licking and keeps on ticking. I for one vote for more doc and more comments. I always here to help.

vincej's avatar
Level 15

@jimmck Nope after the install, I used Lindstroms return mail config thingee which was useful as you can see exactly what L5 sees and boom it worked. The interaction between the .env file and the mail.php file is not in anyway clear from the docs nor Jeffrey's video's. There is always the possibility that out of the 10,000 permutations I tried I missed the exact correct one, but I think not. The mail.php is supposed to override the .env but it does not.

When I reinstalled I did not install Barry's package through composer this time, instead preferring to just install the gist. I have far fewer errors than before, but damned Storm still can't see all of the classes like Laracasts/flash and some of my own classes. Damned annoying.

Now I want to tackle multi authentication ie admins and users. Laravel does not have a clean solution for that. That's really strange for a top of the line framework.

Many thanks again - you are a superstar !

jimmck's avatar

@vincej, What Mail return utility did you use? mail.php does override .env file, otherwise my test would have failed. Also IDEHelper will never catch everything.

vincej's avatar
Level 15

@jimmck I used this:

get('/mail-config',  function() {
    return config('mail');
});

Then I used your mail::raw thingee. Worked great.

lindstrom's avatar

@vincej At the risk of beating this to absolute death and in acknowledgment of the fact the docs could provide more in-depth examples and as Jim noted, as conigured, the variables in your .env will be checked first and if the variable isn't present, it will use the second param in the the mail.php file. For example:

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

If you don't have a MAIL_DRIVER variable set, it will use log. If you use the test route I provided, you can change one or the other and see those changes reflected when you visit the route.

As for your next adventure, Laravel added authorizations and policies in 5.1.11. I haven't dug into it yet other than reading about it, but check it out:

The docs: http://laravel.com/docs/5.1/authorization

Jeffrey covers it in 4 parts starting here: https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/13

And Matt Stauffer here: https://mattstauffer.co/blog/acl-access-control-list-authorization-in-laravel-5-1

vincej's avatar
Level 15

@lindstrom Thanks again,

Yup I saw the L5 doc on authorisation. Thanks for the other bits. That is going to help. Ideally what I want is multiple authentications where Admins are redirected after login to a Dashboard and users to the users page. Curiously L5 appears not to offer this. However, I think I might have figured out a work around using just authorisations.

Are you in Scandinavia as I thought. Just being nosy. I come from UK & Netherlands myself. Cheers !

luddinus's avatar

It happen to me once, I was using "guzzlehttp/guzzle" version > 6... I "downgrade" to version 5 and magic.

manofsteele's avatar

I ran into this same issue also and setup:

Route::get('/mail-config', function() { return config('mail'); });

and realized it was not taking my config settings.

in config/mail.php i had to update the username/password env array from:

'username' => env('user@domain.com'), 'password' => env('password'),

//to 'username' => env('MAIL_USERNAME','user@domain.com'), 'password' => env('MAIL_PASSWORD', 'password'),

then I had to run:

php artisan config:clear

for the changes to take effect.

drove me nuts, but working now!

promatik's avatar

Hi everyone, just to let you know what happened to me (I feel so dumb).

I was having this issue because on my .env file I had the variables duplicated, and empty 🤦

MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="Name"

...

MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
Previous

Please or to participate in this conversation.