php phpmailer错误“无法实例化邮件功能”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1297084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
phpmailer error "Could not instantiate mail function"
提问by sdfor
I'm using the mail()basic example modified slightly for my user id and I'm getting the error "Mailer Error: Could not instantiate mail function"
我正在使用mail()针对我的用户 ID 稍加修改的基本示例,但出现错误“邮件程序错误:无法实例化邮件功能”
if I use the mail function -
如果我使用邮件功能 -
mail($to, $subject, $message, $headers);
it works fine, though I'm having trouble sending html, which is why I'm trying PHPMailer.
它工作正常,尽管我在发送 html 时遇到问题,这就是我尝试 PHPMailer 的原因。
this is the code:
这是代码:
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
print ($body ); // to verify that I got the html
$mail->AddReplyTo("[email protected]","my name");
$mail->SetFrom('[email protected]', 'my name');
$address = "[email protected]";
$mail->AddAddress($address, "her name");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
回答by Mukesh Chapagain
Try using SMTPto send email:-
尝试使用SMTP发送电子邮件:-
$mail->IsSMTP();
$mail->Host = "smtp.example.com";
// optional
// used only when SMTP requires authentication
$mail->SMTPAuth = true;
$mail->Username = 'smtp_username';
$mail->Password = 'smtp_password';
回答by Avinash
$mail->AddAddress($address, "her name");
should be changed to
应该改为
$mail->AddAddress($address);
This worked for my case..
这对我的情况有效..
回答by D.F.
You need to make sure that your from address is a valid email account setup on that server.
您需要确保您的发件人地址是该服务器上设置的有效电子邮件帐户。
回答by Salman A
If you are sending file attachments and your code works for small attachments but fails for large attachments:
如果您正在发送文件附件并且您的代码适用于小附件但无法用于大附件:
If you get the error "Could not instantiate mail function" error when you try to send large emails and your PHP error log contains the message "Cannot send message: Too big" then your mail transfer agent (sendmail, postfix, exim, etc) is refusing to deliver these emails.
如果您在尝试发送大型电子邮件时收到“无法实例化邮件功能”错误,并且您的 PHP 错误日志包含消息“无法发送消息:太大”,那么您的邮件传输代理(sendmail、postfix、exim 等)拒绝发送这些电子邮件。
The solution is to configure the MTA to allow larger attachments. But this is not always possible. The alternate solution is to use SMTP. You will need access to a SMTP server (and login credentials if your SMTP server requires authentication):
解决方案是配置 MTA 以允许更大的附件。但这并不总是可能的。另一种解决方案是使用 SMTP。您将需要访问 SMTP 服务器(如果您的 SMTP 服务器需要身份验证,则需要登录凭据):
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // set the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
PHPMailer defaults to using PHP mail()function which uses settings from php.iniwhich normally defaults to use sendmail (or something similar). In the above example we override the default behavior.
PHPMailer 默认使用 PHPmail()函数,该函数使用php.ini通常默认使用 sendmail(或类似的东西)的设置。在上面的例子中,我们覆盖了默认行为。
回答by Matías Cánepa
This worked for me
这对我有用
$mail->SetFrom("[email protected]","my name", 0); //notice the third parameter
回答by Erenss
Your code looks good, did you forget to install PostFix on your server?
您的代码看起来不错,您是否忘记在服务器上安装 PostFix?
sudo apt-get install postfix
It worked for me ;)
它对我有用;)
Cheers
干杯
回答by Matt Pope
The PHPMailer help docs on this specific errorhelped to get me on the right path.
有关此特定错误的 PHPMailer 帮助文档帮助我走上了正确的道路。
What we found is that php.ini did not have the sendmail_path defined, so I added that with sendmail_path = /usr/sbin/sendmail -t -i;
我们发现 php.ini 没有定义 sendmail_path,所以我添加了 sendmail_path = /usr/sbin/sendmail -t -i;
回答by Alex
Seems in my case it was just SERVER REJECTION. Please check your mail server log / smtp connection accessibility.
在我看来,这只是服务器拒绝。请检查您的邮件服务器日志/smtp 连接可访问性。
回答by lzoesch
I had this issue, and after doing some debugging, and searching I realized that the SERVER (Godaddy) can have issues.
我遇到了这个问题,在进行了一些调试和搜索后,我意识到 SERVER(Godaddy)可能有问题。
I recommend you contact your Web hosting Provider and talk to them about Quota Restrictionson the mail function (They do this to prevent people doing spam bots or mass emailing (spam) ).
我建议您联系您的网络托管服务提供商并与他们讨论Quota Restrictions邮件功能(他们这样做是为了防止人们使用垃圾邮件机器人或群发电子邮件(垃圾邮件))。
They may be able to advise you of their limits, and if you're exceeding them. You can also possibly upgrade limit by going to private server.
他们可能会建议您了解他们的限制,以及您是否超出了限制。您也可以通过转到私人服务器来升级限制。
After talking with GoDaddy for 15 minutes the tech support was able to resolve this within 20 minutes.
在与 GoDaddy 交谈 15 分钟后,技术支持人员能够在 20 分钟内解决此问题。
This helped me out a lot, and I wanted to share it so if someone else comes across this they can try this method if all fails, or before they try anything else.
这对我帮助很大,我想分享它,所以如果其他人遇到这个问题,他们可以尝试这种方法,如果一切都失败了,或者在他们尝试其他任何事情之前。
回答by fiskcn
In my case, it was the attachment size limit that causes the issue. Check and increase the size limit of mail worked for me.
就我而言,是附件大小限制导致了问题。检查并增加对我有用的邮件的大小限制。

