如何在phpmailer中禁用错误消息

如何在phpmailer中禁用错误消息,php,forms,debugging,phpmailer,Php,Forms,Debugging,Phpmailer,我使用phpmailer作为带有附件的contactform,并在php中生成自己的错误消息。 表单和电子邮件工作正常,但当没有填写电子邮件地址,也没有选择要上传的文件时,我从phpmailer收到了这些错误消息 Invalid address: Could not access file: 这是我现在使用的phpmailer的代码: // Software: PHPMailer - PHP email class | //

我使用phpmailer作为带有附件的contactform,并在php中生成自己的错误消息。 表单和电子邮件工作正常,但当没有填写电子邮件地址,也没有选择要上传的文件时,我从phpmailer收到了这些错误消息

Invalid address: Could not access file:
这是我现在使用的phpmailer的代码:

// Software: PHPMailer - PHP email class                                    |
// Version: 5.1 

require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();

$mail->SMTPAuth = FALSE;
$mail->Port     = 25;  
$mail->Host     = "localhost";
$mail->Mailer   = "smtp";
$mail->SetFrom($_POST["user_email"], $_POST["user_name"]);
$mail->AddAddress("myname@myemailcom"); 
$mail->Subject = "Contactform";
$mail->WordWrap   = 80;
$mail->MsgHTML($_POST["user_message"]);

if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['user_attachment']['tmp_name'],$_FILES['user_attachment']['name']); 
}
$mail->IsHTML(true);
if(!$mail->Send()) {
    echo 'some error message';
}
else {
    echo 'success message';
}
经过一些研究,我试图补充:

$phpmailer->SMTPDebug=false; // without result

如何消除这些内置错误消息?

首先,您运行的是非常旧的PHPMailer版本,该版本已经过时,并且使您的站点暴露在一些主要漏洞之下。在你做任何事情之前。我还建议您以PHPMailer提供的当前示例为基础编写代码

在您发布的代码中,您根本没有启用调试输出(默认情况下是关闭的),因此我怀疑您可能没有显示其他代码。您还没有显示调试输出的样子,因此我们无法判断生成它的是否真的是PHPMailer

您的PHPMailer实例被称为
$mail
,而不是
$PHPMailer
,并且
SMTPDebug
属性是一个整数,因此将该行更改为:

$phpmailer->SMTPDebug = 0;

谢谢大家的关注!我会升级