Could not instantiate mail function. Why this error occurring

Rajasekar picture Rajasekar · Dec 22, 2009 · Viewed 126.1k times · Source

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 = "[email protected]";
$mail->FromName = "Rajasekar";
$mail->AddAddress("[email protected]"); // 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.';
}
?>

Answer

Michael Yagudaev picture Michael Yagudaev · Jun 9, 2012

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.