Laravel - Connection could not be established with host smtp.gmail.com [ #0]

后端 未结 13 572
无人及你
无人及你 2020-12-29 04:32

I\'m trying to send an email from Gmail using Laravel from localhost. I\'m getting this error: Connection could not be established with host smtp.gmail.com [ #0]

I\'

相关标签:
13条回答
  • 2020-12-29 04:57

    I had the same error: Connection could not be established with host smtp.gmail.com [ #0] and followed the steps outlined here: https://github.com/swiftmailer/swiftmailer/issues/544.

    Try adding the following lines to _establishSocketConnection() in Swift/Transport/StreamBuffer.php on line 263:

    $options['ssl']['verify_peer'] = FALSE;
    $options['ssl']['verify_peer_name'] = FALSE;
    

    Note that this is not a perfect solution as it involves: a) Hacking core code which may be overwritten in a SwiftMailer update, and b) decreases the security of your app as you're no longer validating the connection. But as a temporary work-around it worked for me.

    0 讨论(0)
  • 2020-12-29 04:58

    This one line change in .env file will make it work

    MAIL_DRIVER=sendmail
    

    If it also has no effect try to switch between the mail port

    MAIL_PORT=587
    

    Or

    MAIL_PORT=465
    

    This will work only if you enable "Allow Less secure app access" under google account

    0 讨论(0)
  • 2020-12-29 04:59

    this worked for me after a long search time, the best configuration :

    'driver' => 'smtp',
    'host' => 'smtp-mail.outlook.com',
    'port' => 587, ( or 25)
    'encryption' => 'tls',
    
    0 讨论(0)
  • 2020-12-29 05:00
    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=test@gmail.com
    MAIL_PASSWORD=testpassword
    
    0 讨论(0)
  • 2020-12-29 05:01

    In your .env file you will need to set the email address and password of your email account:

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=test@gmail.com
    MAIL_PASSWORD=testpassword
    

    and in mail.php

    <?php
    
    return [
        'driver' => env('MAIL_DRIVER', 'smtp'),
        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
        'port' => env('MAIL_PORT', 587),
        'from' => ['address' => 'yourEmail@gmail.com', 'name' => 'Your Title'],
        'encryption' => 'tls',
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'sendmail' => '/usr/sbin/sendmail -bs',
        'pretend' => false,
    ];
    

    and clear the config cache with:

    php artisan config:cache
    
    0 讨论(0)
  • 2020-12-29 05:01

    https://accounts.google.com/DisplayUnlockCaptcha https://www.google.com/settings/security/lesssecureapps

    env

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=test@gmail.com
    MAIL_PASSWORD=test
    MAIL_ENCRYPTION=tls
    /********/
    

    email.php

    'from' => ['address' => 'test@gmail.com', 'name' => 'test'],
    
    0 讨论(0)
提交回复
热议问题