简体   繁体   English

SMTP错误:无法连接

[英]SMTP ERROR: unable to connect

i am getting this error kindly help me 我收到此错误,请帮我

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. 2015-03-06 10:43:16 SMTP错误:无法连接到服务器:由于目标计算机主动拒绝连接,因此无法建立连接。 (10061) 2015-03-06 10:43:16 SMTP connect() failed. (10061)2015-03-06 10:43:16 SMTP connect()失败。 Message could not be sent.Mailer Error: SMTP connect() failed. 无法发送消息。邮件程序错误:SMTP connect()失败。

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';
}

some while ago I also encountered this problem. 前一段时间我也遇到了这个问题。 The server admin is also not very helpful, but from what i have already done, this is the thing that must be checked : 服务器管理员也不是很有帮助,但是从我已经做的事情来看,这是必须检查的事情:

  1. Host, this is the address of the SMTP server, if you want to connect to some server, i believe this is not localhost . 主机,这是SMTP服务器的地址,如果要连接到某些服务器,我相信这不是localhost Example : mail.mycompany.com 示例:mail.mycompany.com
  2. SMTPsecure, there are some method for securing transmission, you can test using SSL or TLS or STARTTLS SMTPsecure,有一些方法可以保护传输,可以使用SSL或TLS或STARTTLS进行测试
  3. Port, test for the correct port. 端口,测试正确的端口。 Commonly it uses port 465, but it can be other. 通常使用端口465,但也可以使用其他端口。 For example STARTTLS uses port 587. 例如,STARTTLS使用端口587。
  4. You can try to analyze the output debug message regarding your error. 您可以尝试分析有关您的错误的输出调试消息。

Please correct me if i'm wrong. 如果我错了,请纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM