現在我試圖在有人提交進入數據庫的評論時發送電子郵件通知。我使用mysql_real_escape_string()
來防止注入,我試圖在電子郵件通知中發送名稱,電子郵件和評論時刪除這些斜槓。數據庫條目代碼已被註釋掉,因爲我不希望每次測試電子郵件系統時都會有條目。Stripslashes()在電子郵件中不起作用
電子郵件發送得很好,但stripslashes()
無法正常工作。例如,如果消息是「不能等待!」該電子郵件將有「評論:不能等待!」。這對我來說很奇怪,因爲當我在頁面上顯示評論時,stripslashses可以正常工作。
這是因爲我沒有將stripslashes()
應用於沒有直接從數據庫中傳出的數據?
$li = mysql_connect($dbHost, $dbUser, $dbPass) or die("Could not connect");
mysql_select_db($dbDatabase, $li) or die ("could not select DB");
$name = mysql_real_escape_string($HTTP_POST_VARS["name"]);
$email = mysql_real_escape_string($HTTP_POST_VARS["email"]);
$comment = mysql_real_escape_string($HTTP_POST_VARS["comment"]);
$date = Date("Y-m-d h:i:s");
/*
$gb_query = "insert into entries
values(0, '$name', '$email', '$comment', '$date')";
mysql_query($gb_query);
$res = mysql_affected_rows();
// See if insert was successful or not
if($res > 0) {
$ret_str="Your guestbook entry was successfully added!";*/
$name2=stripslashes($name);
$email2=stripslashes($email);
$comment2=stipslashes($comment);
$subject = 'New Guestbook Entry Has been Added!';
$message = "Name: $name2\nEmail: $email2\nComment: $comment2";
$to = "[email protected]";
mail($to, $subject, $message);
//header('Location: guestbook.php?ps=1');
//exit(); // End the request
/*
} else {
$ret_str = "There was a problem with your guestbook entry. Please try again.";
}
// Append success/failure message
$gb_str .= "<span class=\"ret\">$ret_str</span><BR>";*/
mysql_close();
你可以發佈你的代碼嗎? –
對不起,我完全忘了添加它。 – tim
http://os-code-web.blogspot.com/2011/04/15-top-php-coding-tutorials-tips-and.html –