【问题标题】:phpMailer send a smtp emailphpMailer 发送 smtp 电子邮件
【发布时间】:2014-06-24 16:07:52
【问题描述】:

我正在尝试使用 phpMailer 发送电子邮件。

我已下载文件并将其放入“path2”。

php 程序有 3 个输入:$email、$subject 和 $body。

这是运行时的错误代码:

2014-06-24 15:48:18 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) SMTP connect() failed. Mailer Error: SMTP connect() failed. 

这是我的代码:

<?php
    require_once("..\path2\class.phpmailer.php");
    date_default_timezone_set('America/Eastern');
    include("..\path2\class.smtp.php");
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug  = 1; 
    $mail->SMTPAuth   = True;
    $mail->SMTPSecure = "SSL";
    $mail->Host = "smtp.live.com";      
    $mail->Port = 465;                  
    $mail->Username   = "self@live.com";
    $mail->Password   = "pass1"; 
    $mail->From="self@live.com";
    $mail->Subject    = $subject;
    $mail->Body=$body;
    $mail->AddAddress($email);
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message sent!";
    }
?>

【问题讨论】:

  • 你可以尝试从你的服务器使用telnet命令,看看是网络错误还是你的php代码错误。
  • telnet cmd 的详细信息?
  • 具体是什么意思?
  • 他在请求命令。

标签: php phpmailer


【解决方案1】:

Telnet 对于测试加密连接不是很有用——openssl 更好。在你的服务器上试试这个:

openssl s_client -crlf -connect smtp.live.com:465

我目前无法从多个国家/地区连接,所以也许微软终于在 1998 年注意到端口 465 上 SSL 的弃用...试试这个吧:

openssl s_client -starttls smtp -crlf -connect smtp.live.com:587

这对我来说效果很好,所以我建议您对代码进行以下更改:

$mail->SMTPSecure = "tls";
$mail->Port = 587;

【讨论】:

    猜你喜欢
    • 2014-10-19
    • 2011-04-06
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多