【问题标题】:Send email with swift mailer using exchange authentication使用交换身份验证通过 swift mailer 发送电子邮件
【发布时间】:2013-06-23 07:39:48
【问题描述】:

我正在尝试使用 Exchange 身份验证通过 swift mailer 发送电子邮件。但是,我似乎无法弄清楚为什么它不起作用。

<?php
require_once( "./application/helpers/swift/swift_required.php" );
$transport =
Swift_SmtpTransport::newInstance( "31.149.66.10", 25 )
    ->setUsername( "username" )
    ->setPassword( 'password' )
    ->setEncryption( "tls" );
$mailer = Swift_Mailer::newInstance( $transport );
$message = Swift_Message::newInstance( "onderwerp" )
->setFrom( array( "from@address.com" ) )
->setTo( array( "to@address.com" ) )
->setBody( "Body van het bericht" );
var_dump( $mailer->send( $message ) );
?>

这给了我错误:Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "nieuwsbrief" using 0 possible authenticators'.

服务器配置为使用 TLS 和基本身份验证(仅在启动 TLS 后提供基本身份验证)。

我看到有些人使用端口 587 进行 TLS 加密,但我无法连接端口 587。这给出了错误:Connection could not be established with host 31.149.66.10 [No route to host #113].

谁能看出我做错了什么?

【问题讨论】:

    标签: php smtp exchange-server swiftmailer


    【解决方案1】:

    如果会抛出 Swift_TransportException 类型的异常,则意味着身份验证失败。

    要及早知道身份验证是否失败并抛出异常,请在创建的 Transport 上调用 start() 方法

    以下清单将帮助您找到此类错误的问题:

    • 检查连接是否在其他邮件客户端/平台上正常工作,使用相同的端口和凭据以及加密
    • 检查您的 php 安装是否未启用 TLS 支持。 您可以使用 PHP function stream_get_transports() 检查您的 PHP 安装中是否存在“tls”和/或“ssl”

    例如,您可以通过在 php.ini 中添加它来添加它

    extension=php_openssl.dll
    
    • 确保没有任何防火墙阻止连接,587 可能被阻止

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 2015-11-23
      相关资源
      最近更新 更多