PHP Mailer在MS Exchange上失败


PHP Mailer fails on MS Exchange

我正试图通过PHP邮件发送电子邮件,我失败了。我得到的错误信息如下:

2014-08-12 12:21:40 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) 2014-08-12 12:21:40    SMTP connect() failed. Mailer Error: SMTP connect() failed.
我的代码如下:我不知道我做错了什么。我很确定所有的信息都是正确的,除了端口。鉴于这是使用microsoft exchange,我使用端口587 -这是我出错的地方吗?
<?php
include("phpmailer/class.phpmailer.php");
$mail             = new PHPMailer();    
$body             = "HellooooO";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPSecure = "tls";
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  
$mail->Host       = "My server name"; 
$mail->Port       = 587;                    
$mail->Username   = "My MS exchange email address"; 
$mail->Password   = "Password";        
$mail->SetFrom('My MS exchange email address', 'First Last');
$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "test email address";
$mail->AddAddress($address, "John Doe");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>

----------- 编辑 -------------------

根据Synchro的评论,我没有使用最新版本的PHP Mailer,我已经修改了代码如下。我仍然无法发送电子邮件,错误信息是一样的…如何检查TLS端口是否打开并正常工作?

<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail ->SMTPDebug = 1;

$mail->isSMTP();                                      
$mail->Host = 'My Server';
$mail->Port = 587;    
$mail->SMTPAuth = true;                               
$mail->Username = 'My email address';                 
$mail->Password = 'My Password';                           
$mail->SMTPSecure = 'tls';                            
$mail->From = 'My email address';
$mail->FromName = 'Mailer';
$mail->addAddress('My Test Email address', 'Joe User');     

$mail->WordWrap = 50;                                 
$mail->isHTML(true);                                  
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

问候和感谢你,g .

不确定这个问题是否已经解决,但是这是典型的防火墙行为。您可以使用Wireshark之类的工具来查看服务器是否正在接收请求。