PHPMAILER Mailer 错误:SMTP connect() 失败(无法访问 php.ini)


PHPMAILER Mailer Error: SMTP connect() failed (No Access to Php.ini)

下午好,

我已经在Phpmailer上工作了几天,无法绕过这些SMTP Connect失败的错误。我已经禁用了防火墙,并仔细检查了我的用户名和密码是否正确。我无法访问我的php.ini文件,因为我的服务器是基于云的(Rackspace)。我联系了rackspace,他们告诉我访问我的.htaccess文件。但是,我找不到有关要添加到.htaccess文件以使phpmailer没有SMTP连接失败错误的任何信息。代码和错误报告如下。 任何和所有的信息都是值得赞赏的。

附言我也查看了我的php_errors.log文件,那里任何地方都没有phpmailer错误!

include("../phpmailer/class.phpmailer.php");
include("../phpmailer/PHPMailerAutoload.php");
include("../phpmailer/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'utf-8';
$mail->ContentType = 'text/html';
$mail->SMTPDebug = 2;
$mail->SMTPAuth   = true;
$mail->SMTPSecure = "ssl";
$mail->Host       = "secure.emailsrvr.com";
$mail->Port       = 465;
$mail->Username   = "xxx@website.com";
$mail->Password   = "password";
$mail->From       = "xxx@website.com";
$mail->FromName   = "xxx";
$mail->AddAddress('xxx@website.com', 'First Name');
$mail->IsHTML(true); // send as HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is a plain-text message body';
$mail->WordWrap   = 80; // set word wrap
$mail->msgHTML(file_get_contents('..contents.htm'), dirname(__FILE__));
//Attach an image file
$mail->addAttachment('');
// HTML body
$body  = "Hello";
if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
}else{
    echo "Message sent!";
}

错误 1:

2014-12-08 17:35:42 Could not access file:
2014-12-08 17:36:03 SMTP ERROR: Failed to connect to server: Connection timed out (110)
2014-12-08 17:36:03 SMTP connect() failed. Mailer Error: SMTP connect() failed.

错误 2:

2014-12-08 17:38:09 Could not access file: 
2014-12-08 17:38:10 SERVER -> CLIENT: 220 smtp17.relay.dfw1a.emailsrvr.com ESMTP - VA Code Section 18.2-152.3:1 forbids use of this system for unsolicited bulk electronic mail (Spam) 
2014-12-08 17:38:10 CLIENT -> SERVER: EHLO everyhome.com 
2014-12-08 17:38:10 SERVER -> CLIENT: 250-smtp17.relay.dfw1a.emailsrvr.com 250-SIZE 75000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250 ENHANCEDSTATUSCODES 
2014-12-08 17:38:10 CLIENT -> SERVER: AUTH LOGIN 
2014-12-08 17:38:10 SERVER -> CLIENT: 334 VXNlcm5hbWU6 
2014-12-08 17:38:10 CLIENT -> SERVER: cGF1bC5oZWNrQGV2ZXJ5aG9tZS5jb20= 
2014-12-08 17:38:10 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 
2014-12-08 17:38:10 CLIENT -> SERVER: S2ltYmVybHkxMTU= 
2014-12-08 17:38:11 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6 
2014-12-08 17:38:11 SMTP ERROR: Password command failed: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6 
2014-12-08 17:38:11 CLIENT -> SERVER: QUIT 
2014-12-08 17:38:11 SERVER -> CLIENT: 221 2.0.0 Bye 
2014-12-08 17:38:11 SMTP connect() failed. Mailer Error: SMTP connect() failed.

拼写错误:

$mail->msgHTML(file_get_contents('..contents.htm'), dirname(__FILE__));
                                    ^--- missing /?

除非您确实有一个名为"..内容.htm"。

至于smtp错误 - 它超时了。 某些secure.emailsrvr.com:465是防火墙/无法从您的PHP服务器访问的。由于这不是编程问题,我们无法真正帮助您 - 您必须弄清楚数据包在何处/如何放入位桶中。

我的php.ini文件,因为我的服务器是基于云的(Rackspace)。我联系了rackspace,他们告诉我访问我的.htaccess文件。

你的php.ini文件中只有sendmail配置,你不必对.htaccess做任何事情,只有当你要在那里添加东西,就像在php.ini文件上一样

您需要查看邮件日志。

问题

tailf/var/log/maillog

如果您在命令行上以获得更好的调试消息。


如果您启用了其他错误日志,这会更好

require_once '../class.phpmailer.php';
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
    $mail->AddReplyTo('name@yourdomain.com', 'First Last');
    //additional mail related code 
} catch (phpmailerException $e) {
    echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
    echo $e->getMessage(); //Boring error messages from anything else!
}

这看起来确实是一个简单的身份验证失败,因此请仔细检查您的用户名和密码。我建议从 PHPMailer 提供的示例之一开始 - 这看起来像是基于一些非常古老的东西,所以还要确保你有来自 github 的最新 PHPMailer。

将您的

代码减少到绝对最小值以消除错误源 - 例如直接设置Body,不要调用msgHTML,不要加载外部内容,不要添加附件 - 只需删除所有非绝对必要的内容。

尝试

在端口 587 上使用"tls"进行连接,您也可以尝试一下AuthType = 'PLAIN'。还要确认 EHLO 响应与您要求连接到的服务器匹配,以防您的 ISP 透明地重定向您。

检查DNS和网络问题也包含在PHPMailer文档中。