Debugging PHP Mail() and/or PHPMailer

I'm quite stuck with a problem sending mail from a PHP script. Some data:

  • Shared hosting, no SSH access, only hosting provider panel
  • PHP version 5.2.5
  • Last year I built a site which had no problems sending mail with the same hosting
  • Let's say the domain is “” and my private address is “” for anonimity's sake in the following code.

Here's the code:

ini_set("display_errors", 1);

$to = "";
$subject = "Hi";
$body = "Test 1\nTest 2\nTest 3";
$headers = 'From:' . "\r\n" .
    'errors-to:' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if (mail($to, $subject, $body, $headers)) {
    echo("Message successfully sent");
} else {
    echo("Message sending failed");

$message = "Hello world";
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->AddAddress("", "Agos");
$mail->SetFrom("","My Site");
$mail->Subject = "Test Message";
$mail->Body = $message;

And here is what I get:

Message sending failed Could not instantiate mail function.

Which is baffling to say the least. Is there anything I can do to get at least some more meaningful errors? Why is code from the class showing up in my file?


It looks like the class.phpmailer.php file is corrupt. I would download the latest version and try again.

I've always used phpMailer's SMTP feature:

$mail->Host = "localhost";

And if you need debug info:

$mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)
                       // 1 = errors and messages
                       // 2 = messages only

Need Your Help

Why is 'Updating the Git index failed' displayed

windows git newline core.autocrlf

I am using Windows. When staging files I get this error.

Can't create working meteor.js project on a vagrant box

mongodb meteor vagrant

I cannot start up a new Meteor application on a Vagrant linux box (running on a Mac). It fails every time with a 'unspecified uncaught exception' in Mongo. I have tried a bunch of things to get this