PHP Mailer错误:无法发送消息。邮件程序错误:SMTP connect()失败。

3
这是我的代码:
require 'phpmailertesting/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'send.one.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'myemailhidden';                 // SMTP username
$mail->Password = 'mypasswordhidden';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also     accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->From = 'myemailhidden';
$mail->FromName = 'My Name';
$mail->addAddress('example@example.com');               // Name is optional

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

我尝试更改端口和安全连接类型为"TSL"和"SSL",但没有效果。我已经查看了现有的答案,但都没有解决问题。有什么建议吗?谢谢。
我启用了SMTP调试器,它显示:"Connection: opening to ssl://send.one.com:465, t=300, opt=array ( ) 2014-12-15 15:46:40 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2014-12-15 15:46:40 SMTP connect() failed"。

telnet send.one.com 465 对我有效。尝试将 $mail->SMTPSecure 行完全删除,看看是否有效? - sjagr
尝试过了,还是同样的错误 :( - user4324207
你的网络主机是谁?可能存在一些出站IPTables规则,阻止你从端口465进行通信。 - sjagr
one.com。我打算尝试使用我的Google账户。看看是否可以成功 :) - user4324207
不行,不能用于 Gmail 邮箱 :( 这里出了什么问题! - user4324207
1
这是他们的说法,意思是你需要找一个更好的网络服务提供商。 - Synchro
3个回答

5

您的托管公司 one.com 故意阻止出站邮件端口,以限制恶意 PHP 脚本。 send.one.com 地址是为外部邮件客户端(例如您的手机、电子邮件客户端等)而设立的,而不是用于从您的网站发送内部邮件脚本的。

根据其有关从您的网站发送电子邮件的支持文档,您必须更改主机到其内部 SMTP 地址 mailout.one.com - 由于这是一个内部中继,因此您还必须使用端口 25 并禁用任何安全性,如 TLS 或 SSL。您还必须禁用身份验证。

以下是正确的配置:

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mailout.one.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Authentication must be disabled
$mail->Username = 'myemailhidden';
$mail->Password = ''; // Leave this blank
$mail->Port = 25;                                    // TCP port to connect to

@SteMain 禁用身份验证,并删除用户名/密码字段。确保您的“发件人”地址属于您的主机域。 - sjagr
@user4324207 你可以试试我的解决方案,它经过测试应该能正常工作。 - Pingui
@sjagr:我尝试了你的答案,现在它显示消息中心,但我仍然没有收到任何邮件。 - pcs
@saina 这超出了这个问题和答案的范围。你应该查找其他关于已发送但未被接收者接收的消息的SO问题,并在找不到解决方案的情况下开始一个新的SO问题。祝你好运。 - sjagr
@sjagr:是的,终于我发了一个问题。但是我还是没有得到答案。不管怎样,谢谢。 - pcs
显示剩余4条评论

0
其他的解决方案对我没有用,但这个可以:
$mail->isSMTP();
$mail->Host = 'mailout.one.com';
$mail->SMTPAuth = false;                            // disable SMTP authentication
$mail->Username = '[your one.com-email]';
$mail->Password = '[your one.com-email password]';
$mail->SMTPSecure = '';                            // leave this blank!
$mail->Port = 25;   

如果这对你有帮助,请让我知道!


-1

刚接触SO,所以不能给你@sjagr投金。

我遇到了这个问题,由于我使用的是one.com,所以来自@sjagr的解决方案没有问题 :)

您可以尝试在您的文件中使用此完整输出,并确保链接所需文档。

<?php

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
//$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host       = "mailout.one.com";
$mail->SMTPAuth   = false;
$mail->Port = 25;
$mail->From = 'your@domain.se';
$mail->FromName = 'Mailer';
$mail->addAddress('sendtothis@domain.se');
$mail->addReplyTo('ireply@domain.se', 'Information');
$mail->addBCC('bcc@example.com');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body    = 'hejehej';
$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, ja e fan inte tom';

} ?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接