HTML 邮件中的斜杠?

发布于 2024-09-13 16:37:04 字数 900 浏览 5 评论 0原文

我正在尝试编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夜雨飘雪 2024-09-20 16:37:04

听起来好像启用了魔术引号: http://www.php.net/manual/ en/security.magicquotes.php

禁用 Magic Quotes 或执行以下操作:

$html = stripslashes($_REQUEST["html"]);

此外,如果您的脚本使用表单提交中的发件人和收件人地址,您将被垃圾邮件发送者发现,他们将通过您的服务器发送数千封电子邮件直到您被互联网上的所有垃圾邮件拦截器拦截。你需要锁定它。

您从提交中添加到邮件标头的任何信息都可能受到损害,请参阅以下内容以获取更多信息: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:

$html = stripslashes($_REQUEST["html"]);

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

や莫失莫忘 2024-09-20 16:37:04

尝试使用 php 函数转换 html。有不少。您可能需要编码、解码。

$html = htmlspecialchars($_REQUEST["html"]);

Try using php functions to convert html. There are quite a few. You might need to encode, decode.

$html = htmlspecialchars($_REQUEST["html"]);
冷弦 2024-09-20 16:37:04

你的 PHP 设置是错误的,有一个像 magic_quotes 这样的设置,你必须禁用它。

Your PHP Settings are wrong, there's a setting like magic_quotes or someting, you have to disable this.

久而酒知 2024-09-20 16:37:04

这个程序对我有用:

$mail_message; //actual email message u want to send.
$message = str_replace("\\n","<br/>",(stripslashes($mail_message)));
$message = str_replace("\\r","<br/>",$message);

this procedure worked for me:

$mail_message; //actual email message u want to send.
$message = str_replace("\\n","<br/>",(stripslashes($mail_message)));
$message = str_replace("\\r","<br/>",$message);
甜警司 2024-09-20 16:37:04

我通过将文本传递给 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.

夜还是长夜 2024-09-20 16:37:04

由于服务器配置的原因,没有办法。

Due to server configurations there is no way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文