views:

339

answers:

2

Hi, 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 “domain.com” and my private address is “[email protected]” for anonimity's sake in the following code.

Here's the code:

<?php
error_reporting(E_ALL); 
ini_set("display_errors", 1);

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

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

require('class.phpmailer.php');
$message = "Hello world";
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->AddAddress("[email protected]", "Agos");
$mail->SetFrom("[email protected]","My Site");
$mail->Subject = "Test Message";
$mail->Body = $message;
$mail->Send();
?>

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?

A: 

Can you possibly send me the actual code in class.phpmailer.php somehow so I can debug? I suspect somewhere there is an error in that which is causing the output before the mail send is sent.

Lee
+1  A: 

It looks like the class.phpmailer.php file is corrupt. I'd download the latest version from

http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/PHPMailer_v5.1.tar.gz/download

and try again.

I've always used phpMailer's SMTP feature:

$mail->IsSMTP();
$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
Stacey Richards
The file was corrupt. Still not working, but at least I get a proper error. Will try setting debug info and /or SMTP after lunch. Thanks!
Agos
everything worked out. thanks!
Agos