PHPMailer error: Could not instantiate mail function

PHPMailer error: Could not instantiate mail function

我查看了 Whosebug 和其他网站上的所有旧帖子,发现很多帖子都有相同的错误,但是 none 的修复工作有效。

以下是我得到的错误:

Mailer Error: Could not instantiate mail function.

是否有遗漏或不正确的地方?

<?php
require '../PHPMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

$mail->Host     = "smtp.gmail.com"; // SMTP server
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "censored@gmail.com";
$mail->Password = "censored";

$mail->setFrom('censored@gmail.com');
$mail->addReplyTo('censored@gmail.com');
$mail->addAddress('censored@gmail.com');
$mail->Subject = 'PHPMailer mail() test';
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

$mail->AltBody = 'This is a plain-text message body';

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>

我找到你遗漏的东西了。

您需要设置这两项才能使其正常工作:

$mail->isSMTP();
$mail->SMTPSecure = 'ssl';