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

查看:179
本文介绍了调试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,仅供以下代码使用。

  • 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.

这是代码:

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

这里是我所得到的:


邮件发送失败
无法实例化邮件功能。

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天全站免登陆