Framework: Error send mail

Created on 6 Mar 2020  路  5Comments  路  Source: laravel/framework

  • Laravel Version: 7.0.1
  • PHP Version: 7.3
  • Database Driver & Version: Mysql

Description:

When trying to send a message through "smtp" an error occurs.

  1. https://github.com/laravel/laravel/blob/master/config/mail.php - the configuration is such
  2. Returns the text: Undefined index: host

Code example 1:

 Mail::mailer('smtp')
                    ->to(config('mail.email_support'))
                    ->send(new TestMailRequest());

Code example 2:

 Mail::to(config('mail.email_support'))
                    ->send(new TestMailRequest());

The error occurs at the stage "createSmtpTransport", the parameter "host" cannot be found.
Link code: https://github.com/laravel/framework/blob/7.x/src/Illuminate/Mail/MailManager.php#L186

Maybe I made a mistake somewhere, but after changing the configuration "mail", this error appears

needs more info

Most helpful comment

Remove this from your mail.php config file

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

and replace it with

'default' => env('MAIL_MAILER', 'smtp'),

All 5 comments

@serderovsh you haven't accidentally emptied your MAIL_HOST env variable have you? https://github.com/laravel/laravel/blob/master/.env.example#L27

@driesvints
My env code
```env
MAIL_MAILER=smtp
MAIL_HOST=mail.domain
MAIL_PORT=465

Everything works when I do this:

mail.php
```php
return = [
'driver' => env('MAIL_DRIVER', 'smtp'),
'mailers' => [
//code default
],

'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
]

Remove this from your mail.php config file

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

and replace it with

'default' => env('MAIL_MAILER', 'smtp'),

I have this problem with queue. I have debugged it and the host index seems to be okay, but as soon as it goes to a queue, it became undefined.

Any idea why?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhiloNL picture PhiloNL  路  3Comments

iivanov2 picture iivanov2  路  3Comments

YannPl picture YannPl  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

JamborJan picture JamborJan  路  3Comments