phpMailer发送smtp电子邮件

时间:2014-06-24 16:07:53

标签: php phpmailer

我正在尝试使用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!";
    }
?>

1 个答案:

答案 0 :(得分:0)

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;