调试 PHP Mail() 和/或 PHPMailer [英] Debugging PHP Mail() and/or PHPMailer

查看:39
本文介绍了调试 PHP Mail() 和/或 PHPMailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直遇到从 PHP 脚本发送邮件的问题.一些数据:

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

  • 共享主机,无 SSH 访问,只有主机提供商面板
  • PHP 5.2.5 版
  • 去年我建立了一个网站,使用相同的主机发送邮件没有问题
  • 假设域是domain.com",为了匿名,在下面的代码中我的私人地址是myaddress@mydomain.com".

代码如下:

<?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();
?>

这是我得到的:

消息发送失败无法实例化邮件功能.

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?

推荐答案

看起来 class.phpmailer.php 文件已损坏.我会下载最新版本,然后再试一次.

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

我一直在使用 phpMailer 的 SMTP 功能:

I've always used phpMailer's SMTP feature:

$mail->IsSMTP();
$mail->Host = "localhost";

如果您需要调试信息:

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

这篇关于调试 PHP Mail() 和/或 PHPMailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆