laravellaravel-7laravel-mail

Mailer [SMTP] is not defined. when I am sending email in laravel 7


I face a problem it the first I see this problem in Laravel 7.

InvalidArgumentException: Mailer [SMTP] is not defined. in file /home1/clinicph/clinic/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php on line 110

and this is my .env file

MAIL_MAILER=SMTP
MAIL_HOST=mail.clinicphase.com
MAIL_PORT=465
MAIL_USERNAME="info@clinicphase.com"
MAIL_PASSWORD=********
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS="info@clinicphase.com"
MAIL_FROM_NAME="${APP_NAME}"

and this is my controller,

Mail::send('emails.contact_us', [
            'name' => $request->name,
            'email' => $request->email,
            'subject' => 'Message from website',
            'mobile_number' => $request->mobile_number,
            'visitor_msg' => $request->message
        ], function ($message) use ($data, $site_email) {
            $message->from($data['email']);
            $message->to($site_email);
            $message->subject('Message from website');
        });

Solution

  • If you look at your config/mail.php file, you'll see which mailers are setup.

    By default in Laravel 7, it has an smtp mailer:

    https://github.com/laravel/laravel/blob/7.x/config/mail.php#L37

    The mailer names are case-sensitive (just like any other configs). So unless you've changed it, you need to use smtp and not SMTP in your .env file.