phpmailer错误“无法实例化邮件功能”

问题描述 投票:34回答:16

我使用的mail()基本示例稍微修改了我的用户ID,我收到错误“Mailer Error:无法实例化邮件功能”

如果我使用邮件功能 -

mail($to, $subject, $message, $headers);

它工作正常,虽然我在发送html时遇到问题,这就是为什么我在尝试使用PHPMailer。

这是代码:

<?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!";
    }
?>
php email phpmailer
16个回答
26
投票

尝试使用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';

1
投票

在我的情况下,导致问题的是附件大小限制。检查并增加为我工作的邮件的大小限制。


0
投票

一个旧线程,但它可能会帮助像我这样的人。我通过在PHP.ini中将SMTP服务器值设置为合法值来解决此问题


0
投票

我也有这个问题。我的解决方案是禁用selinux。我尝试在selinux中允许2个不同的http设置(类似于httpd_allow_email和http_can_connect)并且不起作用,所以我完全禁用它并开始工作。


0
投票

我在发送带有区域字符的文件时遇到了这个问题,例如:VęryRęgióńął file - name.pdf

解决方案是在将文件名附加到电子邮件之前清除文件名。


0
投票

检查sendmail是否已启用,主要是如果您的服务器是由其他公司提供的。


0
投票

对于我有这个问题的价值而且必须进入cPanel,我看到了错误消息

“注意!请通过cpanel插件注册非smtp邮件中使用的电子邮件ID。通过脚本发送的非smtp电子邮件中不允许使用未注册的电子邮件ID。转到Mail部分,在paper_lantern主题中找到”Registered Mail IDs“插件。 “

在cPanel(注册邮件ID)中注册电子邮件并等待10分钟让我的工作。

希望能帮助别人。


-1
投票

我们需要在php.ini文件中更改php.ini文件中的'SMTP'值

EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion\php.ini

11
投票
$mail->AddAddress($address, "her name");

应改为

$mail->AddAddress($address);

这适用于我的情况..


11
投票

这对我有用

$mail->SetFrom("[email protected]","my name", 0); //notice the third parameter

10
投票

您需要确保您的发件人地址是该服务器上的有效电子邮件帐户设置。


9
投票

如果您要发送文件附件,并且您的代码适用于小附件但大型附件失败:

如果您在尝试发送大型电子邮件时收到错误“无法实例化邮件功能”错误,并且您的PHP错误日志包含消息“无法发送邮件:太大”,那么您的邮件传输代理(sendmail,postfix,exim等)拒绝提供这些电子邮件。

解决方案是配置MTA以允许更大的附件。但这并不总是可行的。替代解决方案是use 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默认使用PHP mail()函数,它使用php.ini中的设置,通常默认使用sendmail(或类似的东西)。在上面的示例中,我们覆盖了默认行为。


5
投票

您的代码看起来不错,您是否忘记在服务器上安装PostFix?

sudo apt-get install postfix

它对我有用;)

干杯


3
投票

关于this specific error的PHPMailer帮助文档帮助我走上了正确的道路。

我们发现php.ini没有定义sendmail_path,所以我用sendmail_path = /usr/sbin/sendmail -t -i;添加了


1
投票

在我的情况下似乎只是服务器拒绝。请检查您的邮件服务器日志/ smtp连接可访问性。


1
投票

我遇到了这个问题,经过一些调试和搜索后我意识到SERVER(Godaddy)可能有问题。

我建议您联系您的网络托管服务提供商,并与他们讨论关于邮件功能的Quota Restrictions(他们这样做是为了防止人们做垃圾邮件机器人或群发电子邮件(垃圾邮件))。

他们可能会告诉你他们的极限,如果你超过他们。您也可以通过转到私人服务器来升级限制。

在与GoDaddy交谈15分钟后,技术支持人员能够在20分钟内解决这个问题。

这对我帮助很大,我想分享它,所以如果其他人遇到这个,他们可以尝试这种方法,如果一切都失败,或在他们尝试其他任何事情之前。

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