PHP Mailer错误:无法发送消息.Mailer错误:SMTP connect()失败

时间:2014-12-15 15:43:03

标签: php phpmailer

这是我的代码:

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调试器,这就是它所说的“连接:打开到ssl://send.one.com:465,t = 300,opt = array()2014-12-15 15:46:40 SMTP错误:无法连接到服务器:连接超时(110)2014-12-15 15:46:40 SMTP连接()失败“

3 个答案:

答案 0 :(得分:5)

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

根据他们support document发送来自您网站的电子邮件,您必须将主机更改为其内部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

答案 1 :(得分: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;   

让我知道它是否对你有所帮助!

答案 2 :(得分:-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';

} ?>