Gmail smtp不会发送我的电子邮件

时间:2014-09-30 11:13:05

标签: php

我正在尝试使用Gmail smtp发送电子邮件,但我不发送任何邮件。 我也没有收到任何错误,我只是得到一个空页。 这是我的代码,我希望你能帮助我。

<?php 
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = "MyEmail";
$mail->Password = "Mypassword";
$mail->setFrom('MyEmail');
$mail->addReplyTo('MyEmail');
$mail->addAddress('MyEmail');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->Body = 'This is a plain-text message body';
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>

请注意,我输入了正确的电子邮件和密码。

1 个答案:

答案 0 :(得分:1)

默认情况下,PHPMailer将使用php的mail()函数(sendmail)发送邮件。您需要为phpMailer包含smtp类才能使用SMTP发送邮件

require 'class.phpmailer.php';
require 'class.smtp.php';

您可以从github

获取
相关问题