问题描述
我的代码有效,但是当我发送电子邮件时,我看到这个长块信息以这样开头:
2021-03-06 13:42:26 客户端 -> 服务器:EHLO 本地主机
2021-03-06 13:42:26 客户端 -> 服务器:STARTTLS
2021-03-06 13:42:27 客户端 -> 服务器:EHLO 本地主机
2021-03-06 13:42:27 客户端 -> 服务器:授权登录
2021-03-06 13:42:27 客户端 -> 服务器:[隐藏凭据]
2021-03-06 13:42:27 客户端 -> 服务器:[隐藏凭据]
...然后继续写关于 PHPMailer 的所有信息。
我不想让所有人在他们发送电子邮件后看到它,我该如何隐藏它?
这是我的代码:
if($errore == 0){
$message_email = 'Messaggio inviato da: '.$name.' '.$surname.'<br>';
$message_email .= 'Email: '.$email.'<br>';
$message_email .= 'Telefono: '.$number.'<br>';
$message_email .= 'Oggetto: '.$object.'<br>';
$message_email .= 'Corpo: '.$message.'<br>';
require 'PHPMailer.PHP';
require 'Exception.PHP';
require 'SMTP.PHP';
$mail = new \PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "myemail@gmail.com";
$mail->Password = "mypass";
$mail->IsHTML(true);
$mail->setFrom('bibibibi@gmail.com');
$mail->addAddress('lalala@gmail.com');
$mail->msgHtml($messaggio_email);
$mail->Subject = $object;
if(!$mail->Send()) {
echo "something went wrong";
var_dump($mail);
} else {
echo 'Email sent';
}
解决方法
您需要更改“SMTP 类调试输出模式”。使用 SMTPDebug
属性。
$mail->SMTPDebug = SMTP::DEBUG_OFF;
您的实际值 (1
) 对应于 DEBUG_CLIENT
。
但是您应该使用以下允许的值之一:
- SMTP::DEBUG_OFF:无输出
- SMTP::DEBUG_CLIENT:客户端消息
- SMTP::DEBUG_SERVER:客户端和服务器消息
- SMTP::DEBUG_CONNECTION:作为服务器加上连接状态
- SMTP::DEBUG_LOWLEVEL:嘈杂的低级数据输出,很少需要