SMTP ERROR: unable to connect

SMTP ERROR: unable to connect

我收到这个错误请帮助我

2015-03-06 10:43:16 SMTP ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it. (10061) 2015-03-06 10:43:16 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

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

如有错误请指正