SMTP错误:无法连接


SMTP ERROR: unable to connect

我收到这个错误,请帮助我

2015-03-06 10:43:16 SMTP错误:无法连接到服务器:否由于目标计算机主动拒绝,无法建立连接it。(10061)2015-03-06 10:43:16 SMTP连接()失败。消息可以无法发送。Mailer错误:SMTP连接()失败。

my code is
<?php
require 'classes/class.phpmailer.php';
require 'classes/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 1;                              // Enable verbose debug output
$mail->isSMTP();                                     // Set mailer to use SMTP
$mail->Host = 'localhost';                           // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                              // Enable SMTP authentication
$mail->Username = 'root';                            // SMTP username
$mail->Password = '';                                // SMTP password
$mail->SMTPSecure = 'ssl';                           // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                   // TCP port to connect to
$mail->From = 'bces11-51@xxxxxx.edu.pk';
$mail->FromName = 'usman';
$mail->addAddress('usmanxxxx@yahoo.com', 'usmanxxx');     // Add a recipient
$mail->addAddress('usmanxxxxx@gmail.com');                // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'subject is send email';
$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';
}

不久前我也遇到了这个问题。服务器管理员也不是很有帮助,但根据我已经做的,这是必须检查的事情:

  1. 主机,这是SMTP服务器的地址,如果你想连接到某个服务器,我相信这不是localhost。示例:mail.mycompany.com
  2. SMTPsecure,有一些方法可以保护传输,您可以使用SSL或TLS或STARTTLS进行测试
  3. 端口,测试正确的端口。通常使用端口465,但也可以是其他端口。例如,STARTTLS使用端口587
  4. 您可以尝试分析有关错误的输出调试消息

如果我错了,请纠正我。