出于某种原因,当通过 PHP mail(); 函数发送 HTML 格式的电子邮件时,每个 (') 撇号之前都会出现 () 反冲。这不是错字或类似的东西。我已经检查过其他符号,它只发生在撇号上。太奇怪了。它发生在表单文本区域中的参数$message内(请注意,它不是全部内容,只要我知道我的正则表达式不允许在其他任何地方使用撇号)。这可能与 UTF-8 编码有关吗?实在是太奇怪了。它曾经发生在其他人身上吗,有什么解决方案吗?这不是一个大问题,只是不是一个通常的问题。
$to = 'example@email.com';
$subject = "Hey, you've got a new message!";
$headers = "MIME-Version: 1.0" . "'r'n";
$headers .= "Content-type:text/html;charset=UTF-8" . "'r'n";
$headers .= 'From: <example@email.com>' . "'r'n";
$content = "<html><head><style>
.bold {
font-weight: bold;
}
.contiguous {
display: inline-block;
}
.correct-spacing {
white-space: pre-wrap;
}
.grey {
color: #373737;
}
.lilac {
color: #7b68ee;
}
</style></head><body>
<div class='bold contiguous lilac'>From: </div><div class='contiguous grey'>$name</div><br/>
<div class='bold contiguous lilac'>E-mail: </div><div class='contiguous grey'>$email</div><br/>
<div class='bold contiguous lilac'>Phone: </div><div class='contiguous grey'>$phone</div><br/><br/>
<div class='correct-spacing grey'>$message</div>
</body></html>";
mail($to, $subject, $content, $headers);
echo 'Your message has been sent. Thank you!';
收到的电子邮件示例:
发件人:名称示例
电子邮件: example@email.com
电话: +123456789
嘿,你好
这是个测试。让我们希望它有效。
问候
您magic_quotes_gpc
已启用;此功能在 5.3 中已弃用,并在 5.4 中完全删除,但旧版本默认情况下仍会启用它。
阅读本文,了解如何在无法升级安装时在现有环境中禁用魔术引号。
您还可以使用 stripslashes() 在发送消息之前删除反斜杠。
$clean_message = stripslashes ($content);
mail($to, $subject, clean_message, $headers);