PHP Mailer not working

Hello All,

I am trying to send mail using phpmailer class
my test_mail.php file is

$mail  = new PHPMailer(); // defaults to using php "mail()"
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\\]",'',$body);
$mail->From  = "";
$mail->FromName   = "First Last";
$mail->Subject    = "PHPMailer Test Subject via mail()";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->AddAddress("", "My Name");
$mail->AddAttachment("images/phpmailer.gif");             // attachment
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";

The error I am getting is
Mailer Error: Could not instantiate mail function.

Please provide me the solution.

Sorry if this is a stupid question, but are you using PHP5 or higher? If you aren’t, you won’t be able to use any classes at all as they weren’t introduced until version 5 of PHP.

By default Method to send mail in PHPMailer is set to mail() function. If this mail() function is disabled then it gives that error.
So please check on your server if that mail function works correctly(without PHPMailer).

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


I am using PHP 5.
Yeah, I have checked, and my php mail() function is working properly without PHPMailer.

Wrong. PHP 4 has classes. They’re not well implemented but they are there.

can anyone help me out.

I guess this is because your smtp configuration is not properly being received to class.smtp.php:
I found somewhere in the internet pages:

sounds like your sendmail isn’t working, assuming linux, or smtp if windows. That error occurs trying to use the ‘mail’ built-in php mail() codepath, if the mail function fails. could also be that your php isn’t properly configured for mail(). Oh, and the “language string” thing means that it was unable to load the language files. maybe a folder changed? or phpmailer isn’t in the same path?

Generally stuff like this happens when SOMETHING changes on your system. A service isn’t running that should be, you upgraded something, etc. PHP version change, php INI options changed, sendmail or SMTP service change (depending on linux vs windows)… This stuff really doesn’t just stop working. :wink: I assume you’ve rebooted?

So please checkout those things first.

Thanks rajug,

But everything if fine with the system.Also I have tried with php’s mail() function and it is working properly.
the example I have given above is one of the example from phpmailer downloads.
But, I am not getting what’s wrong with the code or where I have to made changes.
Also smtp is configured…
Please help me out?


Since this is not the usual error as far as i know, so please try to get help from your best friend GOOGLE with the same error message as keyword. It must point you to a helpful direction I hope.

Daft question maybe, but is the path to the include correct?

ini_set("display_errors", 1);
error_reporting( E_ALL);

include_once ('class.phpmailer.php');
$mail = new PHPMailer();

$mail->Host = "smtp.example.tld"; // or $mail->Host = "ssl://";

// optional
#$mail->SMTPAuth = true;
#$mail->Username = "";
#$mail->Password = "yourmailpassword";

$body = $mail->getFile('contents.html');
$body = preg_replace("/\\\\\\/", "", $body);
$mail->From = "";
$mail->FromName = "First Last";
$mail->Subject = "PHPMailer Test Subject via mail()";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->AddAddress("", "My Name");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
if ( ! $mail->Send())
    echo "Mailer Error: " . $mail->ErrorInfo;
    echo "Message sent!";