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

后端 未结 13 722
无人及你
无人及你 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 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

     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
    

提交回复
热议问题