Could not instantiate mail function. Why this erro

2019-01-03 18:36发布

When I'm trying to send mail through PHPMailer, i'm getting this error message. My code is below:

<?
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.';
}
?>

17条回答
Root(大扎)
2楼-- · 2019-01-03 18:36

Make sure that you also include smtp class which comes with phpmailer:

// for mailing
require("phpmailer/class.phpmailer.php");
require("phpmailer/class.smtp.php");
查看更多
老娘就宠你
3楼-- · 2019-01-03 18:37

Check with your host to see if they have any hourly limits to emails being sent.

查看更多
▲ chillily
4楼-- · 2019-01-03 18:38

This a system error.

Check error of the system with:

tail /var/log/httpd/error_log

It can be any reason.

查看更多
我只想做你的唯一
5楼-- · 2019-01-03 18:39

Just revisiting the old thread you can debug PHPMailer in depth by adding:

print_r(error_get_last());

this will print out the exact error for you which is causing the default php mail() to break.

Hope it helps somebody.

查看更多
Bombasti
6楼-- · 2019-01-03 18:41

In Ubuntu (at least 12.04) it seems sendmail is not installed by default. You will have to install it using the command sudo apt-get install sendmail-bin

You may also need to configure the proper permissions for it as mentioned above.

查看更多
再贱就再见
7楼-- · 2019-01-03 18:42

I just had this problem and found in my apache error log that sendmail was'nt installed, after installation it was all working as it should!

root@web1:~$ tail /var/log/apache2/error.log
sh: 1: /usr/sbin/sendmail: not found
查看更多
登录 后发表回答