我正在尝试使用gmail smtp服务器作为php中继来发送电子邮件。我在webmatrix服务器编程,我使用PHPMailerAutoload库发送电子邮件。我的操作系统是Windows 7 64位。我已经配置php.ini使用gmail smtp服务器。当运行代码我得到成功消息但没有电子邮件发送。有人可以帮我找到问题,谢谢。这是我的代码的一部分:
$mail = new PHPMailer(true);
//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "example"; // GMAIL username
$mail->Password = "password"; // GMAIL password
}
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom("example@gmail.com", "name");
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
$mail->SMTPDebug = true;
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}
答案 0 :(得分:0)
下载包装文件 PHPMailer,导入文件,如下所示。
require '../PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "example"; // GMAIL username
$mail->Password = "password"; // GMAIL password
}
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom("example@gmail.com", "name");
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
$mail->SMTPDebug = true;
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}