我的代码可以工作,但是当我发送电子邮件时,我看到这样长的信息 block ,其开头如下:
2021-03-06 13:42:26 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:26 CLIENT -> SERVER: STARTTLS
2021-03-06 13:42:27 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:27 CLIENT -> SERVER: AUTH LOGIN
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
...并继续编写有关 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 = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="167b6f737b777f7a56717b777f7a3875797b" rel="noreferrer noopener nofollow">[email protected]</a>";
$mail->Password = "mypass";
$mail->IsHTML(true);
$mail->setFrom('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ffdf6fdf6fdf6fdf6dff8f2fef6f3b1fcf0f2" rel="noreferrer noopener nofollow">[email protected]</a>');
$mail->addAddress('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f434e434e434e6f48424e4643014c4042" rel="noreferrer noopener nofollow">[email protected]</a>');
$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;
与 DEBUG_CLIENT
对应的实际值 (1
)。
但是您应该使用以下允许的值之一:
- SMTP::DEBUG_OFF:无输出
- SMTP::DEBUG_CLIENT:客户端消息
- SMTP::DEBUG_SERVER:客户端和服务器消息
- SMTP::DEBUG_CONNECTION:作为 SERVER 加连接状态
- SMTP::DEBUG_LOWLEVEL:嘈杂、低级数据输出,很少需要
关于php - 如何隐藏PHPMailer的日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66506373/