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 “myaddress@mydomain.com” for anonimity's sake in the following code.
Here's the code:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$to = "myaddress@mydomain.com";
$subject = "Hi";
$body = "Test 1
Test 2
Test 3";
$headers = 'From: info@domain.com' . "
" .
'errors-to: myaddress@mydomain.com' . "
" .
'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("myaddress@mydomain.com", "Agos");
$mail->SetFrom("info@domain.com","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?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…