简体   繁体   English

使用Google Apps帐户在Laravel 5中发送电子邮件不起作用

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

i am now building one quite big sized enterprise grade web application on our production server. 我现在正在生产服务器上构建一个大型企业级Web应用程序。

while i was developing on local development server, sending mail was not a big concern, but in the live step it became a big pain in my butt. 当我在本地开发服务器上进行开发时,发送邮件并不是什么大问题,但是在实时操作中,这成了我的麻烦。

i've searched like more than 3days and tried to use mandrill, postfix and sendmail driver options in the Laravel, still i could not get it happen. 我已经搜索了超过3天,并试图在Laravel中使用mandrill,postfix和sendmail驱动程序选项,但仍然无法实现。

so anyone, who experienced developing sending emails on Laravel with google apps account??? 这样的人,谁有经验开发使用Google Apps帐户在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

above is my .env file of the web application 上面是我的Web应用程序的.env文件

and log shown below is the log, when the mail send fails 当邮件发送失败时,下面显示的日志是日志

[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: [2015-07-02 17:56:16] production.ERROR:异常“ Swift_TransportException”,消息为“预期响应代码250,但代码为” 535”,消息为“ 535-5.7.8,用户名和密码未接受。了解更多at ^ M 535 5.7.8 https://support.google.com/mail/answer/14257 gs7sm4872423pbc.6-/ h​​ome / thecorp-admin / Services / TheMandarin / Trinity / vendor / swiftmailer / swiftmailer中的gsmtp ^ M“' /lib/classes/Swift/Transport/AbstractSmtpTransport.php:383堆栈跟踪:

just incase i will provide some useful information. 以防万一我会提供一些有用的信息。

above shown link does not work with google apps accounts 以上显示的链接不适用于Google Apps帐户

This is an answer using gmails smtp server 这是使用gmails smtp服务器的答案

In your App\\Config\\mail.php 在您的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',

If you are using two step verification you need to get an app password. 如果您使用两步验证,则需要获取应用密码。 To do this go to your google account, sign in settings and add a new app. 为此,请转到您的Google帐户,登录设置并添加一个新应用。 You will need to select other. 您将需要选择其他。 Google will give you a password which you will need to use in this config file Google会为您提供一个密码,您需要在此配置文件中使用该密码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM