phpMailer:无法实例化邮件功能 [英] phpMailer: Could not instantiate mail function

查看:65
本文介绍了phpMailer:无法实例化邮件功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表单,该表单使用 phpMailer 将结果通过电子邮件发送给网站所有者.当然,在添加所有者的电子邮件地址之前,我会使用我的电子邮件地址来测试表单是否有效.当我使用我的电子邮件时,表单可以完美发送,但是,当我使用所有者的地址时,它会抛出错误无法实例化邮件功能"并且不会发送表单.该错误仅发生在与所有者域关联的电子邮件地址中.知道为什么会发生这种情况吗?

I created a form that uses phpMailer to email the results to the website owner. Of course, before I add the owner's email address I use mine to test that the form works. When I use my email the form sends perfectly, however, when I use the owner's address it throws the error "could not instantiate mail function" and won't send the form. The error only occurs with email addresses associated with the owner's domain. Any idea why this could be happening?

如果我在命令行中输入它,它工作正常:

If I type this into the command line it works fine:

echo 'test' | mail -s 'test' me@example.com

我最初没有使用 SMTP,但现在配置如下.错误消息现在是SMTP 错误:以下收件人失败 xxx@somedomain.com",最终结果仍然相同.它可以通过电子邮件发送到多个 gmail 测试地址,但对所有者的 email@hisdomain.com 存在问题.此外,使用 SMTPDebug 它现在产生错误RCPT TO 命令失败:550 这里没有这样的用户"但是,当通过 gmail、outlook 等发送电子邮件时,所有者的电子邮件可以正常工作.

edit: I wasn't initially using SMTP, but it's now configured as shown below. The error message is now "SMTP Error: The following recipients have failed xxx@somedomain.com" and the end result is still the same. It can e-mail to a number of gmail test addresses but has issue with the owner's email@hisdomain.com. Further, with SMTPDebug it's now producing the error "RCPT TO command failed: 550 No Such User Here" The owner's e-mail, however, works without issue when e-mailed through gmail, outlook, etc.

phpMailer 代码:

phpMailer code:

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->Debugoutput = "error_log";
$mail->Host = "mail.mydomain.com";
$mail->SMTPAuth = true;
$mail->Username = "admin@mydomain.com";
$mail->Password = "XXXXXXXXXXXXXXX";
$mail->CharSet = 'UTF-8';
$mail->AddReplyTo($emailAddress);
$mail->SetFrom("admin@mydomain.com");

$mail->AddAddress($toAddress,$toName);

$mail->Subject = $emailSubject;
$mail->isHTML(true);
$mail->Body = $emailBody;
$mail->AltBody = strip_tags($emailBody);

// Attempt to send the e-mail       
if (!$mail->send()) {
    //error handling
}

推荐答案

Set $mail->SMTPDebug = 2; 这样你就可以看到服务器说了什么,并且 阅读故障排除指南.

Set $mail->SMTPDebug = 2; so you can see what the server has to say, and read the troubleshooting guide.

您使用的是未加密的身份验证,这不是一个好的组合,而且许多服务器都不允许这样做.添加这个:

You're using authentication without encryption, which is not a good combination and many servers won't allow that. Add this:

$mail->SMTPSecure = 'tls';
$mail->Port = 587;

您的代码基于旧示例,因此您可能也在使用旧版本的 PHPMailer;从 github 获取最新的.

You've based your code on an old example, so you're probably using an old version of PHPMailer too; get the latest from github.

这篇关于phpMailer:无法实例化邮件功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆