在 Laravel 5 中使用 google 应用程序帐户发送电子邮件不起作用

sending email in Laravel 5 with google apps account does not work

我现在正在我们的生产服务器上构建一个相当大的企业级 Web 应用程序。

我在本地开发服务器上开发的时候,发邮件不是什么大问题,但是在live这一步就成了我的一个大痛

我已经搜索了超过 3 天,并尝试在 Laravel 中使用 mandrill、postfix 和 sendmail 驱动程序选项,但我仍然无法实现。

所以有没有开发过使用 google 应用程序帐户在 Laravel 上发送电子邮件的人???

APP_DEBUG=true
APP_KEY=my app key

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mandrillapp.com
MAIL_USERNAME=admin@themandarin.co.kr
MAIL_PASSWORD=my api key

以上是我的 web 应用程序的 .env 文件

下图为邮件发送失败时的日志

[2015-07-02 17:56:16] production.ERROR: exception 'Swift_TransportException' with message 'Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at^M 535 5.7.8 https://support.google.com/mail/answer/14257 gs7sm4872423pbc.6 - gsmtp^M "' in /home/thecorp-admin/Services/TheMandarin/Trinity/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383 Stack trace:

以防万一我会提供一些有用的信息。

上图 link 不适用于 google 应用程序帐户

这是使用 gmails smtp 服务器的回答

在你的App\Config\mail.php

/*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "log"
    |
    */

    'driver' => 'smtp',

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Mailgun mail service which will provide reliable deliveries.
    |
    */

    'host' => 'smtp.gmail.com',

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Port
    |--------------------------------------------------------------------------
    |
    | This is the SMTP port used by your application to deliver e-mails to
    | users of the application. Like the host we have set this value to
    | stay compatible with the Mailgun e-mail application by default.
    |
    */

    'port' => 587,

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => ['address' => 'sender@email.co.uk', 'name' => 'Ted notification'],

    /*
    |--------------------------------------------------------------------------
    | E-Mail Encryption Protocol
    |--------------------------------------------------------------------------
    |
    | Here you may specify the encryption protocol that should be used when
    | the application send e-mail messages. A sensible default using the
    | transport layer security protocol should provide great security.
    |
    */

    'encryption' => 'tls',

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Username
    |--------------------------------------------------------------------------
    |
    | If your SMTP server requires a username for authentication, you should
    | set it here. This will get used to authenticate with your server on
    | connection. You may also set the "password" value below this one.
    |
    */

    'username' => 'yourname@email.com',

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Password
    |--------------------------------------------------------------------------
    |
    | Here you may set the password required by your SMTP server to send out
    | messages from your application. This will be given to the server on
    | connection so that the application will be able to send messages.
    |
    */

    'password' => 'myPassword',

如果您使用两步验证,您需要获取应用密码。为此,请转到您的 google 帐户,登录设置并添加一个新应用。您将需要 select 其他。 Google 会给你一个密码,你需要在这个配置文件中使用这个密码