php laravel 5.2.20发送smtp邮件

时间:2016-02-23 12:33:23

标签: php laravel smtp

我想在php中使用laravel 5.2.20发送smtp邮件  但是我收到了这个错误

  Whoops, looks like something went wrong.

1/1
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/answer/14257 ra1sm17783395pab.24 - gsmtp
"

我的config / mail.php文件:

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'example@gmail.com', 'name' => 'example'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('example@gmail.com'),
'password' => env('example_pwd'),
'sendmail' => '/usr/sbin/sendmail -bs',

这是我的laravel 5.2.20框架mail.php,但我不会更新我的.env文件中的任何内容。在我的laravel框架中,Dotenv.php文件是他们的但是.env不在这里。我需要更新哪一个......

我的控制器代码如下:

$user = Users::findOrFail($id);

Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
    //echo "<pre>";print_r($user->email);
    //echo "<pre>";print_r($user->name);
    //exit;
    $m->from('example@gmail.com', 'Your Application');

    $m->to($user->email, $user->name)->subject('Your Reminder!');
});

1 个答案:

答案 0 :(得分:1)

发生错误Authentication Required。 您需要为SMTP设置输入用户名和密码,如果没有创建它,请将它们放在.env文件中

cp .env.example .env
php artisan key:generate

MAIL_DRIVER=smtp
MAIL_HOST=your_SMTP HOST
MAIL_PORT=YOUR SMTP PORT
MAIL_USERNAME=USERNAME
MAIL_PASSWORD=PASSWORD
MAIL_ENCRYPTION=null