【问题标题】:WinServer 2012 r2 + PHP(wamp64) PHPMailer error “Could not instantiate mail function”WinServer 2012 r2 + PHP(wamp64) PHPMailer 错误“无法实例化邮件功能”
【发布时间】:2019-03-06 09:28:37
【问题描述】:

我尝试了 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 模块的可用性并且它存在,所以关于模块没有问题。

【问题讨论】:

  • 您是否尝试过使用 SMTP 到 localhost 而不是使用mail() 函数(即您是否调用$mail-&gt;isSMTP())?
  • 是的,我是使用 localhost 和 PHPMailer 完成的。
  • 只有在您使用mail() 时才会出现“无法实例化”错误,因此不会出现这种情况。请使用SMTPDebug = 2 显示您的代码和调试输出。
  • @Synchro 我已经经历了(可能是你的)答案来自:github.com/PHPMailer/PHPMailer/issues/1006。特别SMTPDebug = 3,但没有什么比运气更重要的了:(
  • 请发布您的代码和调试输出,以便我们查看!

标签: phpmailer windows-server-2012-r2 php-7.2 wamp64


【解决方案1】:

两个错误。

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

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

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

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

【讨论】:

    猜你喜欢
    • 2015-08-19
    • 2019-07-24
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 2013-10-08
    相关资源
    最近更新 更多