Laravel 5.3 - SwiftMailer错误:503 AUTH(#5.5.1)

时间:2017-05-22 15:57:52

标签: php laravel email smtp swiftmailer

我正在尝试通过SMTP发送电子邮件(无身份验证)。 这是我的.env设置:

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=tls

正如您所见,我的邮件服务器需要使用tls加密进行身份验证,并且在同一台服务器上,通过PHPMailer(没有Laravel),我可以正确发送电子邮件。事实是,当我尝试通过Laravel发送邮件时(使用mailable),我收到以下错误:

Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "503", with message "503 AUTH first (#5.5.1)
"

我试过空的用户名和密码,ssl加密,没有加密,不同的端口..我只是无法通过Laravel发送电子邮件。

在这里你可以看到我的mailable的构造和构建方法:

public $customerName;
public $customerEmail;
public $emailSubject;
public $emailMessage;


public function __construct($customerName, $customerEmail, $emailSubject, $emailMessage)
    {
        $this->customerName = $customerName;
        $this->customerEmail = $customerEmail;
        $this->emailSubject = $emailSubject;
        $this->emailMessage = $emailMessage;
    }


public function build()
    {
        return $this->view('emails.send');
    }

我错过了什么/做错了吗?我似乎找不到解决方案..

提前谢谢大家。

1 个答案:

答案 0 :(得分:0)

您可以发送未经身份验证的电子邮件,这是我在config/mail.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", "sendmail", "mailgun", "mandrill", "ses",
|            "sparkpost", "log", "array"
|
*/

'driver' => env('MAIL_DRIVER', 'sendmail'),

/*
|--------------------------------------------------------------------------
| 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.mailgun.org'),

/*
|--------------------------------------------------------------------------
| 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' => env('MAIL_FROM_ADDRESS', 'noreply@something.com'),
    'name' => env('MAIL_FROM_NAME', 'Whatever'),
],

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

'password' => env(null),

/*
|--------------------------------------------------------------------------
| 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',

/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/

'markdown' => [
    'theme' => 'default',

    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

];

发送它:

$userArr = array();    
Mail::send('mail.yourviewname', $userArr, function($message) use ($userArr) {
                $message->bcc('someone@something.com', 'Someone');
                $message->to($userArr['email'] ,  $userArr['name'])->subject('Blah blah');
                $message->from('noreply@something.com','Whatever');
            });