我想使用PHPMailer发送电子邮件?给出错误

时间:2014-08-28 05:10:55

标签: php phpmailer

**Error:**SMTP NOTICE: EOF caught while checking if connected SMTP connect() failed.
Mailer Error: SMTP connect() failed. 

我的代码是:

<?php
require('class.phpmailer.php');
//require_once('class.phpmailer.php');
//require_once("inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();// create a new object
$mail ->IsSMTP(); // enable SMTP
$mail ->SMTPDebug = 1; // debugging: 1 = errors and messages, 2                                = messages only 
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 465
$mail->IsHTML(true);
$mail->Username = "biz.online321@gmail.com";
$mail->Password = "mudunuru%^&";
$mail->SetFrom("example@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("varma.sfi123@gmail.com");
print $mail;
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}

你的帮助将被上诉

1 个答案:

答案 0 :(得分:0)

这是你的问题:

$mail->SMTPSecure = 'ssl';
$mail->Port = 587;

您正在尝试将SSL与非SSL端口进行通信。这样做:

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

我还建议您获取latest version of PHPMailer并将代码基于随附的示例。