【问题标题】:Trying to send mail in Laravel 5.2尝试在 Laravel 5.2 中发送邮件
【发布时间】:2017-04-26 13:11:40
【问题描述】:

我正在尝试使用 laravel 5.2 发送电子邮件。但它抛出了这个错误

预期的响应代码为 250,但得到代码“530”,消息为“530 5.7.0” 必须先发出 STARTTLS 命令。 6sm52599778wjt.5 - gsmtp"

这是我的ma​​il.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | 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",
    |            "ses", "sparkpost", "log"
    |
    */

    'driver' => env('MAIL_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' => env('MAIL_HOST', 'smtp.zoho.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' => env('MAIL_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' => 'fics@ficsuk.com', 'name' => 'fics'],

    /*
    |--------------------------------------------------------------------------
    | 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' => env('MAIL_ENCRYPTION', 'ssl'),

    /*
    |--------------------------------------------------------------------------
    | 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' => env('MAIL_USERNAME','fics@ficsuk.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' =>env('MAIL_PASSWORD','*****'),

    /*
    |--------------------------------------------------------------------------
    | Sendmail System Path
    |--------------------------------------------------------------------------
    |
    | When using the "sendmail" driver to send e-mails, we will need to know
    | the path to where Sendmail lives on this server. A default path has
    | been provided here, which will work well on most of your systems.
    |
    */

    'sendmail' => '/usr/sbin/sendmail -bs',

];

这是我的邮件功能

 Mail::send('emails.contact',$data,function($message) use($mail)
                {
                    $message->to('fics@ficsuk.com')->subject('Scholar enquiry');
                });

.env 文件

MAIL_DRIVER= smtp
MAIL_HOST=smtp.zoho.com
MAIL_PORT=993
MAIL_USERNAME=you@yourdomain.com
MAIL_PASSWORD=*****
MAIL_ENCRYPTION=lts

这是我第一次在 laravel 中发送电子邮件。那么请问我的代码有什么问题?

【问题讨论】:

    标签: php email laravel-5 laravel-5.2


    【解决方案1】:

    如果你愿意

    指定'encryption'=&gt; env('MAIL_ENCRYPTION', 'ssl')
    你必须使用'port' =&gt; env('MAIL_PORT', 465)
    .env 文件

    MAIL_ENCRYPTION=ssl
    MAIL_PORT=465 
    

    如果你愿意

    然后指定'port' =&gt; env('MAIL_PORT', 587)
    你必须使用'encryption'=&gt; env('MAIL_ENCRYPTION', 'tls')
    .env 文件

    MAIL_ENCRYPTION=tls
    MAIL_PORT=587
    

    您收到错误是因为您在尝试通过端口587 连接时将加密指定为ssl,该端口预计运行STARTTLS 命令以进行TLS 加密。

    【讨论】:

    • 您是否在.env 文件中指定了MAIL_ENCRYPTION=ssl
    • 刚刚看到.env 文件中有MAIL_ENCRYPTION=lts 如果您使用端口587 将其更改为MAIL_ENCRYPTION=tls,如果您使用端口465 将其更改为@987654340 @
    • 在您的.env 文件中将MAIL_PORT=993 更改为MAIL_PORT=587MAIL_ENCRYTION=tls
    • 我的 . env 文件和 mail.php
    • 您能发布您当前的config/mail.php.env 文件内容吗?你是在本地开发机器上还是在像 Godaddy 这样的共享主机上?
    【解决方案2】:

    只需将配置文件夹中的 mail.php 更改为:

    'username' => env('MAIL_USERNAME','fics@ficsuk.com'),
    'password' =>env('MAIL_PASSWORD','*****'),
    

    到:

    'username' => 'your@emailaddress',
    'password' => 'your_password',
    

    【讨论】:

      猜你喜欢
      • 2016-10-29
      • 2016-05-23
      • 2016-09-18
      • 1970-01-01
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      相关资源
      最近更新 更多