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

问题描述 投票:2回答:1

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

但是,我仍然遇到同样的问题。此外,已检查端口25在此处运行无防火墙问题。

如果有人能帮助我,我真的很感激。

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

server fault回答谢谢

UPDATE

//To test is via basic mail function
/*
mail("[email protected]", "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 = "[email protected]";
$mail->FromName = "Full Name";

//To address and name
$mail->addAddress("[email protected]"); //Tried $mail->addAddress("[email protected]", "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模块的可用性,因此没有关于模块的问题。

phpmailer windows-server-2012-r2 php-7.2 wamp64
1个回答
1
投票

两个错误。

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

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

PHPMailer提供的所有SMTP代码示例都遵循此模式,并在故障排除指南中进行了详细记录。

总而言之,这就是为什么您需要在发布前阅读,阅读文档,并在您的问题中发布您的代码。

© www.soinside.com 2019 - 2024. All rights reserved.