Framework: Mail (smtp): password and username not set in config

Created on 1 Mar 2017  Â·  21Comments  Â·  Source: laravel/framework

  • Laravel Version: 5.4.12
  • PHP Version: HipHop VM 3.18.1 (rel)
  • Database Driver & Version: Ver 15.1 Distrib 10.1.21-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Description:

If set in either config/mail.php, .env, or both, when using SMTP authentication over TLS or SSL, username and password are not set in config.

From a route, dd(Config::get('mail')); prints a configuration that misses username and password.

Steps To Reproduce:

Configure mail using either the global config/mail.php or .env file, eq.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=...
MAIL_ENCRYPTION=tls

Open matching outgoing ports (465 for ssl or 587 for tls). Authentication to the smtp server should fail (error 530). Server reports credentials are not set.

Most helpful comment

Fixed it by doing
'username' => env('MAIL_USERNAME','[email protected]')
Rather than
'username' => env('[email protected]')
in /config/mail.php

All 21 comments

This doesn't look as a framework issue to me, could be that your configs are cached. Please ask on the forums.

The forums are full of people who report the same issue, and I am 100%
certain my configs are not cached. I have a test route, I dd them in
real-time, switch back and forth between tls and ssl, my configs are
updated right before my eyes - and password and username are and remain
null.

On Mar 1, 2017 23:17, "Mohamed Said" notifications@github.com wrote:

This doesn't look as a framework issue to me, could be that your configs
are cached. Please ask on the forums.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/framework/issues/18170#issuecomment-283368386,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAuftAwSjZVpoZBRVYfPkQ1mHdVq9hqIks5rhYwEgaJpZM4MPOkZ
.

dd(Config::get('mail')); returns correct credentials for me, can you please point me to the posts in forums where the same issue is reported?

Will do asap (tomorrow). Thank you for your reply.

On Mar 1, 2017 23:28, "Mohamed Said" notifications@github.com wrote:

dd(Config::get('mail')); returns correct credentials for me, can you
please point me to the posts in forums where the same issue is reported?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/framework/issues/18170#issuecomment-283371846,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAuftECzr6on-yqQJ889uQ6rIXJix95bks5rhY6sgaJpZM4MPOkZ
.

So: just to be on the safe side, I tried again to refresh my cache
php artisan config:cache

The issue is still there. The following threads are among many that report
the same problem:
http://stackoverflow.com/questions/22192133/laravel-default-mail-not-working
http://stackoverflow.com/questions/32515245/how-to-to-send-mail-using-gmail-in-laravel-5-1
https://laracasts.com/discuss/channels/laravel/sending-email-problem-with-gmail?page=1

Now, this is a just a hunch, but if the issue appears to be sporadic, the
common denominator might be HHVM. Ie. this could be some kind of low-level
issue between core components and HHVM.

I am going to install php7 and verify this again. Will keep you posted asap.

No. Issue is identical with php7 (stable) and hhvm.

What happens if you run composer dump-autoload -o? This command sometimes solves booting/settings issues.

Generating optimized autoload files

Issue is the same.

Swift_TransportException in AbstractSmtpTransport.php line 386:
Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required.

If I dump the configuration, I get:

array:9 [â–¼
  "driver" => "smtp"
  "host" => "smtp.gmail.com"
  "port" => "587"
  "from" => array:2 [â–¶]
  "encryption" => "tls"
  "username" => null
  "password" => null
  "sendmail" => "/usr/sbin/sendmail -bs"
  "markdown" => array:2 [â–¼
    "theme" => "default"
    "paths" => array:1 [â–¶]
  ]
]

If I force the configuration from within the route (eq. set the username and password actively), I can then send email.

I can't reproduce your issue, but I can give you _some_ workflow I use when stuck with similar problems.

Run php artisan config:cache, open bootstrap/cache/config.php and look for the 'mail' array. If 'username' is empty, add it directly in config/mail.php, rerun config:cache and look again.
If it's there, have a look for a second 'mail' array in config.php. Then it gets overwritten somewhere. Search in the whole app for the keyword ('username'). I have 11 matches. If you see nothing suspicious, look for 'username'. I have 97 matches. If there is nothing out of the ordinary, try double quotes. The following could help you further.

Open vendor/laravel/framework/src/Illuminate/Mail/MailServiceProvider.php, at line 90 in registerSwiftMailer() add dd(Config::get('mail'), refresh the browser and see what rolls out.

I know it's dirty debugging but as I don't have a deep inside of the inner workings of Laravel, it's my way of pinpointing errors along the way. If the registry of the app config itself goes wrong, I have no idea how to work that out. Tinker can be helpful in many cases but I'm sure your 'username' and 'password' will be empty there too.

For kicks and giggles, call

Config::set('mail.username', 'yourusername');
Config::set('mail.password', 'yourpassword');

just before you send the email, or just before you call dd. Just to see if it is picking up the new configs.

Yeah it does.

On Mar 3, 2017 05:44, "Clayton Stone" notifications@github.com wrote:

For kicks and giggles, call

Config::set('mail.username', 'yourusername');
Config::set('mail.password', 'yourpassword');

just before you send the email. Just to see if it is picking up the new
configs.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/framework/issues/18170#issuecomment-283791732,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAuftCEer29Yt5OzDF06ZK9sHR3alQOBks5rhzgxgaJpZM4MPOkZ
.

Curious if you ever made any progress with this. I have no answers, just very intrigued by the problem.

I don't this it's a framework issue as I can't replicate and based on the fact that many laravel apps use the mail feature already and it's working normally, checking the links you shared and all seem to be environment specific issues.

Closing the issue for now but please feel free to ping me if you every found that there's an actual bug in the framework core.

This is going straight to the pwnies for the lamest vendor response EVER.

...For anyone who missed the subtitles: there is nothing that indicates it
is an "environment issue". In any of the linked threads - and tens of
similar threads since Laravel 5. All affected users seem to have defaulted
to a workaround.

As for me, I have spun a fresh Ubuntu on Linode, a fresh composer and
Laravel, and found myself facing the issue two (get) routes into it.
Reported accurately about it, have in the past accurately reported a hhvm
bug to Mr. Potencier and the Facebook team (- hhvm/memcached
incompatibility with Symfony memcached session driver), yet all I get is a
fumble about presumed "environment problems".

...

One inch further down that road and you might wake up as Donald Trump (it's
ALL fake news, BILLIONS of websites use smtp and laravel and there is no
bug...).

God what has this world come to.

On Mar 14, 2017 00:30, "Mohamed Said" notifications@github.com wrote:

Closed #18170 https://github.com/laravel/framework/issues/18170.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/framework/issues/18170#event-997558991, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAuftHxlkKk_OdYzhouxfI5dHPrdK0Tpks5rlW8agaJpZM4MPOkZ
.

This has nothing to do with SMTP as far as I can tell, from what I understand your issue is that for some reason the username and password configuration are set to null when you try to check them:

From a route, dd(Config::get('mail')); prints a configuration that misses username and password.

Since you're the only one here who can generate the issue, can you please use your experience as a developer and try to dig deeper into the core and see where is the piece of code that reads all configuration options correctly but for some reasons drop only the two keys you mentioned' username and password

Will do. Have little time right now but I will investigate asap.

On Mar 14, 2017 00:54, "Mohamed Said" notifications@github.com wrote:

This has nothing to do with SMTP as far as I can tell, from what I
understand your issue is that for some reason the username and password
configuration are set to null when you try to check them:

From a route, dd(Config::get('mail')); prints a configuration that misses
username and password.

Since you're the only one here who can generate the issue, can you please
use your experience as a developer and try to dig deeper into the core and
see where is the piece of code that reads all configuration options
correctly but for some reasons drop only the two keys you mentioned'
username and password

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/framework/issues/18170#issuecomment-286170160,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAuftIS-DKjbddL5SdltROauTf7c0LRPks5rlXTegaJpZM4MPOkZ
.

Guys, I'm fully on @maurocolella side. Confirming exact same f%%n problem on clean laravel v.5.1!

Solution:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_ENCRYPTION=tls
SMTP_USERNAME=yyyy
SMTP_PASSWORD=xxxx

Experiencing the same issue, but @rus-ik 's solution does not work for me.

Fixed it by doing
'username' => env('MAIL_USERNAME','[email protected]')
Rather than
'username' => env('[email protected]')
in /config/mail.php

Scroll down in your .env file and note that there is a

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

that was part of the default... adding to above part does nothing because later ones overrule it. This took too long to diagnose :laughing: :blush:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixsanz picture felixsanz  Â·  3Comments

CupOfTea696 picture CupOfTea696  Â·  3Comments

kerbylav picture kerbylav  Â·  3Comments

iivanov2 picture iivanov2  Â·  3Comments

PhiloNL picture PhiloNL  Â·  3Comments