20

当我尝试通过 PHPMailer 发送邮件时,我收到此错误消息。我的代码如下:

<?
require("phpmailer/class.phpmailer.php"); // First we require the PHPMailer libary in our script
$mail = new PHPMailer(); // Next we create a new object of the PHPMailer called $mail
$mail->From = "rajasekar.kcet@gmail.com";
$mail->FromName = "Rajasekar";
$mail->AddAddress("rajasekar.kcet@gmail.com"); // This is the adress to witch the email has to be send.
$mail->Subject = "First PHP Email message"; // This is the subject  of the email message.
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHP."; // This is the actual email message
if(!$mail->Send()) // Now we send the email and check if it was send or not.
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
   echo 'Message has been sent.';
}
?>
4

17 回答 17

42

在 Ubuntu(至少 12.04)中,默认情况下似乎未安装 sendmail。您必须使用命令安装它 sudo apt-get install sendmail-bin

如上所述,您可能还需要为其配置适当的权限。

于 2012-06-09T18:55:32.423 回答
13

我用了这行代码

if($phpMailer->Send()){

    echo 'Sent.<br/>';

}else{

    echo 'Not sent: <pre>'.print_r(error_get_last(), true).'</pre>';

}

找出问题所在。原来,我在安全模式下运行,在第 770 行或其他地方,第五个参数 ,$params被赋予mail(),在安全模式下运行时不支持。我只是将其注释掉,瞧,它奏效了:

$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header/*, $params*/);

它在MailSendPHPMailer 的 -function 中。

于 2012-01-22T21:59:34.987 回答
7

我刚遇到这个问题,在我的 apache 错误日志中发现 sendmail 没有安装,安装后它一切正常!

root@web1:~$ tail /var/log/apache2/error.log
sh: 1: /usr/sbin/sendmail: not found
于 2013-08-15T08:46:28.893 回答
3

Had same problem. Just did a quick look up apache2 error.log file and it said exactly what was the problem:

> sh: /usr/sbin/sendmail: Permission denied

So, the solution was to give proper permissions for /usr/sbin/sendmail file (it wasn't accessible from php).

Command to do this would be:

> chmod 777 /usr/sbin/sendmail

be sure that it even exists!

于 2011-11-19T13:08:02.030 回答
2

要重新访问一个旧线程,我的问题是其中一个“AddressTo”电子邮件地址无效。删除该电子邮件地址会消除该错误。

于 2014-09-19T18:56:43.083 回答
2

确保您还包括 phpmailer 附带的 smtp 类:

// for mailing
require("phpmailer/class.phpmailer.php");
require("phpmailer/class.smtp.php");
于 2009-12-22T07:33:06.843 回答
2

尝试使用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';
于 2011-08-22T08:54:02.307 回答
1

这是一个系统错误。

检查系统的错误:

tail /var/log/httpd/error_log

这可以是任何原因。

于 2010-10-27T21:17:01.090 回答
1

尝试使用不是 gmail 的地址。他们不允许(据我所知)smpt 访问以发送邮件。上周我在做一个简单的邮件程序,他们也不使用默认端口发送,并要求您通过 https 传输

于 2010-01-06T23:12:24.960 回答
1

请与您的房东核实,看看他们是否对发送的电子邮件有每小时限制。

于 2011-07-30T05:39:10.617 回答
1

只需重新访问旧线程,您就可以通过添加以下内容来深入调试 PHPMailer:

print_r(error_get_last());

这将为您打印出导致默认 php mail() 中断的确切错误。

希望它可以帮助某人。

于 2015-08-16T08:45:46.390 回答
1

如此处所述,“这意味着您的 PHP 安装未配置为正确调用 mail() 函数(例如,您的 php.ini 中未正确设置 sendmail_path),或者您没有安装和配置本地邮件服务器。”

在我的情况下,我必须在我的虚拟主机的设置中允许 mail() 功能(“激活 mail() 队列”)。

于 2016-07-07T10:24:09.887 回答
0

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

于 2013-06-05T08:40:33.913 回答
0

我已经解决了我的问题(对于 wamp)

    $mail->IsSMTP(); 

    $mail->Host='hote_smtp'; 

corse 将 hot_smtp 更改为正确的值

于 2013-05-15T08:58:58.127 回答
0

“无法实例化邮件函数”是 PHPMailer 报告对 mail() 的调用(在邮件扩展中)失败的方式。(所以您使用的是“邮件”邮件程序。)

您可以尝试在调用 PHPMailer::MailSend 中的 mail() 之前删除 @s 并查看是否有错误被静默丢弃。

于 2010-02-20T19:31:23.373 回答
0

我有同样的错误。回复是导致问题的原因。我删除了它。

$email->AddReplyTo( $admin_email, $admin_name ); 
于 2016-06-30T17:32:41.327 回答
0

在 CentOS 中,这可能是由 SELinux 策略引起的。执行以下代码查看是否启用。

getsebool httpd_can_sendmail

您可以通过调用以下命令来启用它。-P 参数使其永久化。

setsebool -P httpd_can_sendmail 1
于 2018-01-10T13:29:48.573 回答