WinServer 2012 r2 + PHP(wamp64) PHP邮件程序错误“无法实例化邮件功能”

WinServer 2012 r2 + PHP(wamp64) PHPMailer error “Could not instantiate mail function”

我尝试了 win server 2012 r2 相关答案中提示的所有步骤,包括其相关答案和特定的 PHPMailer。

但是,我仍然 运行 同样的问题。此外,已检查端口 25 运行 这里没有防火墙问题。

如果有人能帮助我,我将不胜感激。

注意:
Win server 2012 r2 relates 回答
PHPMailer 回答

server fault 回答 谢谢

更新

//To test is via basic mail function
/*
mail("from_to_email@example.com", "Test Subject", "Test Message");
*/

//To Test via PHPMailer 

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';

//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = "from_email@example.com";
$mail->FromName = "Full Name";

//To address and name
$mail->addAddress("to_email@example.com"); //Tried $mail->addAddress("to_email@example.com", "test name"); and third param too. 

//Send HTML or Plain Text email
$mail->isHTML(true); //Tried with false too.

$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPDebug = 3;
$mail->SMTPSecure = 'ssl';

// optional
// used only when SMTP requires authentication  
$mail->SMTPAuth = true;
$mail->Username = SMTP_EMAIL_HERE;
$mail->Password = SMTP_PASS_HERE;

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

甚至,我通过 online SMTP Tool 尝试了我的 SMTP 凭据并且它工作正常但上面的代码不是。

注意: 我验证了 PHP/Apache 模块的可用性,所以模块没有问题。

两个错误。

你没有调用 isSMTP(),所以你的 SMTP 配置的 none 有任何效果,它使用 mail() 函数,正如我在评论中所说的那样。

在您的 SMTP 配置中,您在端口 587 上使用 SMTPSecure = ‘ssl’。该组合将不起作用;要么更改为端口 465,要么切换到 ’tls’ 模式。

PHPMailer 提供的所有 SMTP 代码示例都遵循此模式,并且在故障排除指南中有大量记录。

总而言之,这就是为什么您需要在 post、阅读文档和 post 问题中的代码之前进行搜索。