我很难从PHP脚本发送邮件。一些数据:
下面是代码:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$to = "myaddress@mydomain.com";
$subject = "Hi";
$body = "Test 1\nTest 2\nTest 3";
$headers = 'From: info@domain.com' . "\r\n" .
'errors-to: myaddress@mydomain.com' . "\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("myaddress@mydomain.com", "Agos");
$mail->SetFrom("info@domain.com","My Site");
$mail->Subject = "Test Message";
$mail->Body = $message;
$mail->Send();
?>我得到的是:
邮件发送失败,无法实例化邮件功能。
这至少可以说是令人费解的。我能做些什么来至少得到一些更有意义的错误吗?为什么来自类的代码会出现在我的文件中?
发布于 2010-05-24 11:13:19
看起来class.phpmailer.php文件已经损坏了。我会下载最新版本,然后再试一次。
我一直使用phpMailer的SMTP特性:
$mail->IsSMTP();
$mail->Host = "localhost";如果您需要调试信息:
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages onlyhttps://stackoverflow.com/questions/2896280
复制相似问题