简体   繁体   中英

Laravel 5.4 SMTP emails not working

I am using laravel 5.4 and configured gmail smtp details for sending emails. Below is code and return expection error.

Email Code:

try {

    Mail::raw('Text', function ($message) {
        $message->to('lpkapil@mailinator.com');
    });
} catch (\Exception $e) {
    echo "<pre>";
    print_r($e->getMessage());
    print_r($e->getCode());
    echo "</pre>";
    die();
}

Returned Execption Message & Error code

  • Error Message:

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

  • Error Code:

    530

Gmail smtp details used:

MAIL_HOST: smtp.gmail.com
MAIL_PORT: 587
MAIL_ENCRYPTION: tls
username: gmail id
password: password

Please suggest a solution.

This is a easy way to send mails using Laravel.You can use this function on your controller. You have to make a blade template file as example "emailfile.blade.php" with what ever the details you want to show on the email and pass the variables to that blade using the inputs array as I mentioned below.

   $inputs = array(
        'name'=> 'Your Name',
        'address' =>'Your Address',
        'company' =>'Your Company',
    );


        Mail::send('emailfile', $inputs, function ($message) {
            $message->from('sender@gmail.com', 'Sender Name');
            $message->to('reciver@gmail.com',$name=null)->subject('Mail Subject!');
            $message->cc('cc@gmail.com');
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM