laravel Expected response code 250 but got code “530”

会有一股神秘感。 提交于 2019-12-29 07:42:37

问题


Im trying to Mail in Laravel 5.1

my mail.php code is

 return [
     'driver' => env('MAIL_DRIVER', 'smtp'),
     'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
     'port' => env('MAIL_PORT', 587),
     'from' => ['address' => 'myemail@gmail.com', 'name' => 'sample'],
     'encryption' => env('MAIL_ENCRYPTION', 'tls'),
     'username' => env('MAIL_USERNAME'),
     'password' => env('MAIL_PASSWORD'),
     'sendmail' => '/usr/sbin/sendmail -bs',
     'pretend' => env('MAIL_PRETEND', false),

 ];

my .env file is

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null

my function to email is

public function sendEmailVerification()
{
    $user = $this->user;//retrieved by $request->user() in __construct

    Mail::send('emails.verifyemail', ['user' => $user], function ($m) use ($user) {
        $m->from('myemail@gmail.com, 'sample');

        $m->to($user->email, $user->name)->subject('Verify Email');
    });
}

Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. l188sm21749863pfl.28 - gsmtp" error appears every time i call my function.


回答1:


you need to enable your 2 step verification from gmail account.

https://myaccount.google.com/security

then use the generated key from there to your ENV_PASSWORD instead your real password.




回答2:


I had the same problem. I changed,

MAIL_ENCRYPTION=null to 
MAIL_ENCRYPTION=tls 

php artisan config:cache

and it worked.




回答3:


Use SSL and port 465 like this:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=mail@gmail.com
MAIL_PASSWORD=12345678
MAIL_ENCRYPTION=ssl

100% will work.




回答4:


change your MAIL_ENCRYPTION = null to MAIL_ENCRYPTION = ssl or MAIL_ENCRYPTION = tls. i had this issue before and changing to MAIL_ENCRYPTION = tls worked for me. also make sure that your mail settings in config\mail.php is the same as .env file




回答5:


After enabling logging to the mail from the less secured devices, make sure that .env file contains the following configurations:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_email@gmail.com
MAIL_PASSWORD="your_passwrod_here"
MAIL_ENCRYPTION=tls

Make sure that your password is rounded by the double quotes "".

Make sure that your mail.php file contains configurations like the following:

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'your_email@gmail.com'),
    'name' => env('MAIL_FROM_NAME', 'your_email'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),

And don't forget to close the server and run php artisan config:clear to clear the configuration cache.

This worked for me



来源:https://stackoverflow.com/questions/42574375/laravel-expected-response-code-250-but-got-code-530

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!