0

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.

Community
  • 1
  • 1
Kapil Yadav
  • 650
  • 1
  • 5
  • 29
  • 1
    I think this has already been solved here: https://stackoverflow.com/questions/32515245/how-to-to-send-mail-using-gmail-in-laravel-5-1 – Denis Solakovic Aug 21 '17 at 11:19

1 Answers1

1

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');
        });
Thiwanka
  • 97
  • 1
  • 8
  • Thank you, Email sending method i am using correctly, Just needed to create an application password for gmail and enabling two factor authentication in gmail. – Kapil Yadav Sep 06 '17 at 18:20