Kim*_*cks 5 php swiftmailer laravel
我有一个问题,使用swiftmailer与客户端的SMTP微软Exchange服务器.
要进行故障排除,我正在考虑用其他东西更换swiftmailer.
我的整个设置都在内部网络上.所以根本没有mailgun或sendgrid.
如何在Laravel中为swiftmailer使用替代库以进行故障排除?
这也是我在Laravel上尝试使用swiftmailer时得到的日志
<< 250-xxx.internal.abc.com Hello [xxx.xx.xxx.xx]
250-SIZE 36700160
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250 XSHADOW
>> STARTTLS
<< 500 5.3.3 Unrecognized command
!! Expected response code 220 but got code "500", with message "500 5.3.3 Unrecognized command
Run Code Online (Sandbox Code Playgroud)
有人让我尝试MAIL_ENCRYPTION为null和dd(config('mail.encryption')),所以下面是答案:
码:
try {
Mail::send('emails.test', [], function ($m) {
$m->from('xxx@client.com', 'Your Application')->to('me@me.com');
dd(config('mail.encryption'));
var_dump('executed');
});
} catch (Exception $e) {
var_dump($e->getMessage());
var_dump($e->getTraceAsString());
}
Run Code Online (Sandbox Code Playgroud)
结果:
null 打印出来的字符串executed不是.
明确使用加密设置为null的swiftmailer传输
try {
// Create the Transport
$transport = \Swift_SmtpTransport::newInstance();
$transport->setUsername('xxx@client.com')
->setPort(25)
->setHost('smtp.internal.client.com')
->setEncryption(null);
// Create the Mailer using your created Transport
$mailer = \Swift_Mailer::newInstance($transport);
$logger = new \Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
$message = new \Swift_Message('Wonderful Subject');
$message->setFrom(['xxx@client.com' => 'John Doe']);
$message->setTo(['me@me.com'])->setBody('Here is the message itself');
// // Send the message
$numSent = $mailer->send($message);
} catch(\Swift_TransportException $e) {
var_dump('test');
var_dump($e->getMessage());
var_dump($e->getTraceAsString());
}
Run Code Online (Sandbox Code Playgroud)
结果:
www-data@server:~/html/laravel-app$ php artisan email:send
string(4) "test"
string(127) "Failed to authenticate on SMTP server with username "xxx@client.com" using 0 possible authenticators"
string(2503) "#0 /var/www/html/a3qp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(332): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
Run Code Online (Sandbox Code Playgroud)
与第二部分相同,但明确将加密设置为'tls'.我得到的错误信息与最顶层的错误信息相同.
有人让我在第一部分中取出dd系列这是我得到的
string(8) "executed"
[Swift_TransportException]
Failed to authenticate on SMTP server with username "xxx@client.com" using 0 possible authenticators
Run Code Online (Sandbox Code Playgroud)
更新
您尝试连接的 SMTP 服务器不理解该STARTTLS命令。为了防止该STARTTLS命令被尝试,您必须通过在文件中设置MAIL_ENCRYPTION环境变量来禁用加密。null.env
下一个问题是,根据EHLO响应,SMTP 服务器不接受任何身份验证方法。如果是这样,该行250-AUTH还将包括它接受的方法(例如250-AUTH PLAIN DIGEST-MD5)。
为了防止身份验证尝试,您必须在文件中设置MAIL_USERNAME环境变量。null.env
总而言之,您的.env文件应该包含以下几行:
MAIL_ENCRYPTION=null
MAIL_USERNAME=null
Run Code Online (Sandbox Code Playgroud)
这将禁用 tls 加密并禁用身份验证。