PHP邮件程序在MS Exchange上失败

时间:2014-08-12 12:30:35

标签: php ms-office phpmailer outlook-2010 exchange-server-2010

我正在尝试通过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.

我的代码如下。我不知道我在哪里弄错了。我很确定所有信息都是正确的,但端口除外。鉴于这是使用微软交换我使用端口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!";
}

?>

----------- EDIT -------------------

根据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。

1 个答案:

答案 0 :(得分:0)

不确定这是否已经治愈,但这是典型的防火墙行为。您可以使用Wireshark之​​类的东西来查看服务器是否正在接收请求。