【问题标题】:PHP Mailer error: Message could not be sent.Mailer Error: SMTP connect() failedPHP Mailer 错误:无法发送消息。Mailer 错误:SMTP 连接()失败
【发布时间】:2014-12-15 15:43:02
【问题描述】:

这是我的代码:

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 connect() failed"

【问题讨论】:

  • telnet send.one.com 465 为我工作。完全取出$mail-&gt;SMTPSecure 行,看看是否可行?
  • 试过了。仍然失败并出现同样的错误:(
  • 谁是您的虚拟主机?可能有一些传出 IPTables 规则阻止您从端口 465 进行通信。
  • one.com。我将尝试使用我的谷歌帐户。看看这是否有效:)
  • 这是他们的说法,您需要找到更好的 ISP。

标签: php phpmailer


【解决方案1】:

您的托管公司 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

【讨论】:

  • 仍然没有运气:(同样的错误信息。真的很奇怪!
  • @SteMain 禁用身份验证,并删除用户名/密码字段。确保您的“发件人”地址属于您的托管域。
  • 是的,它奏效了。我使用端口 25,没有身份验证。这是什么意思?与 one.com 有什么关系?
  • @SteMain 没错。 one.com 可能出于安全原因这样做 - 但这个问题是您的托管公司特有的,并且不太可能在许多其他主机中发现。
  • @SteMain 不幸的是,它仍然对我不起作用 - 你能不能展示一下对你有用的完整设置?谢谢!
【解决方案2】:

其他解决方案对我不起作用;这个做到了:

$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;   

如果它也对你有帮助,请告诉我!

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2016-08-14
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多