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


Gmail smtp does not send my emails

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

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

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

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

您可以从github 获得它