简体   繁体   English

Laravel 5.4 SMTP电子邮件不起作用

[英]Laravel 5.4 SMTP emails not working

I am using laravel 5.4 and configured gmail smtp details for sending emails. 我正在使用laravel 5.4并配置了Gmail smtp详细信息来发送电子邮件。 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 预期的响应代码为250,但得到的代码为“ 530”,消息为“ 530 5.7.1”

  • Error Code: 错误代码:

    530 530

Gmail smtp details used: 使用的Gmail smtp详细信息:

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. 这是使用Laravel发送邮件的简便方法。您可以在控制器上使用此功能。 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. 您必须制作一个刀片模板文件作为示例“ emailfile.blade.php”,其中包含要在电子邮件中显示的详细信息,然后使用输入数组将变量传递到该刀片,如下所述。

   $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');
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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