0

有谁知道我的代码有什么问题?当用户在文本区域框中输入文本时,引号会在它们之前呈现反斜杠,单引号的行为方式相同。我尝试了几种代码组合,但没有任何效果。有人可以帮我吗?谢谢。

这是我的代码:-------->

/* Email Variables */
$emailSubject = 'You have received an inquiry from your website';
$webMaster = 'info@3elementsreview.com';

/* Data Variables */
$first = $_POST['First'];
$last = $_POST['Last'];
$email = $_POST['E-Mail'];
$message = $_POST['Message'];



$body = <<<EOD
<span style="color:#454545; font-weight:bold; font-size:1.6em;">$first</span><br>

<span style="color:#454545; font-weight:bold; font-size:1.6em;">$last</span><br>

<span style="color:#454545; font-weight:bold; font-size:1.6em;">$email</span><br>
<br>
<span style="color:#252525; font-size:1.4em;">$message</span><br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);
4

3 回答 3

1

使用 PHP 的stripslashes()函数尝试以下操作:

返回一个去掉反斜杠的字符串。(\'变成'等等。)

双反斜杠 ( \\) 被制成单个反斜杠 ( \)。

$first = Trim(stripslashes($_POST['First']));
$last = Trim(stripslashes($_POST['Last']));
$email = Trim(stripslashes($_POST['E-Mail']));
$message = Trim(stripslashes($_POST['Message']));
于 2013-08-21T20:51:57.140 回答
1

在使用之前禁用magic_quotes_gpc您的php.ini或调用您的数据。strip_slashes()

此外,您还将很快吸引垃圾邮件发送者,因为您的脚本可以很容易地用于群发邮件,因为它是可破解的,因此任何人都可以将自己的标题(包括 CC:或 BCC:到您的邮件)注入。请参阅有关标头注入的这篇(快速搜索)文章:http ://www.dreamincode.net/forums/topic/228389-preventing-php-mail-header-injections/

于 2013-08-21T20:32:46.137 回答
0

尝试使用这个

var_dump(preg_replace("@[/\\\]@", "", $variable));
于 2013-08-21T21:05:28.987 回答