HTML 邮件中的斜杠?
我正在尝试编写一个 html 邮件发送器,但我有一个问题,它显示斜杠。
我的代码的一部分:
<?php
$sender = $_REQUEST["sender"];
$to = $_REQUEST["to"];
$html = $_REQUEST["html"];
$send = $_REQUEST["send"];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=' . $ce . "\r\n";
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $sender . "\r\n";
mail($to, $title, $html, $headers);
?>
<form action="html.php" method="post">
Sender: <input type="text" name="sender" value="[email protected]">
HTML content: <textarea cols="40" rows="5" name="html"></textarea>
<input type="submit" value="Send">
</form>
当我在文本中输入 html 代码并将其发送到 gmail 时,它显示奇怪的斜杠。我在这里犯了什么错误?
I'm trying to write an html mail sender but I have a problem, it shows slashes.
Part of my code:
<?php
$sender = $_REQUEST["sender"];
$to = $_REQUEST["to"];
$html = $_REQUEST["html"];
$send = $_REQUEST["send"];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=' . $ce . "\r\n";
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $sender . "\r\n";
mail($to, $title, $html, $headers);
?>
<form action="html.php" method="post">
Sender: <input type="text" name="sender" value="[email protected]">
HTML content: <textarea cols="40" rows="5" name="html"></textarea>
<input type="submit" value="Send">
</form>
When I type an html code to the textare and send it to gmail, it show weird slashes. What mistake I'm making here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
听起来好像启用了魔术引号: http://www.php.net/manual/ en/security.magicquotes.php
禁用 Magic Quotes 或执行以下操作:
此外,如果您的脚本使用表单提交中的发件人和收件人地址,您将被垃圾邮件发送者发现,他们将通过您的服务器发送数千封电子邮件直到您被互联网上的所有垃圾邮件拦截器拦截。你需要锁定它。
您从提交中添加到邮件标头的任何信息都可能受到损害,请参阅以下内容以获取更多信息:http://www.phpsecure.info/v2/article/MailHeadersInject.en.php
Sounds like Magic Quotes are enabled: http://www.php.net/manual/en/security.magicquotes.php
Either disable Magic Quotes or do this:
Also, if your script uses a from and to address from the form submission, you WILL be found by spammers who will send thousands of emails through your server until you are blocked by every spam blocker on the internet. You need to lock that down.
Any information you add to the mail header from a submission can be compromised, see this for more information: http://www.phpsecure.info/v2/article/MailHeadersInject.en.php
尝试使用 php 函数转换 html。有不少。您可能需要编码、解码。
Try using php functions to convert html. There are quite a few. You might need to encode, decode.
你的 PHP 设置是错误的,有一个像 magic_quotes 这样的设置,你必须禁用它。
Your PHP Settings are wrong, there's a setting like magic_quotes or someting, you have to disable this.
这个程序对我有用:
this procedure worked for me:
我通过将文本传递给 stripslashes() 来解决这个问题;
它不是(或者不再是)由 magic_quotes 引起的,因为它在 PHP 5.4 中被删除了。 PHP 似乎会自动向来自 HTML 表单的文本添加斜杠,作为(也许?)一种安全措施。
I fixed this by passing the text through stripslashes();
It's not (or no longer, anyway) caused by magic_quotes, as that was removed in PHP 5.4. PHP seems to automatically add slashes to text that comes from HTML forms, as (maybe?) a security measure.
由于服务器配置的原因,没有办法。
Due to server configurations there is no way.