2014-01-08 54 views
0

當我收到從網上問答我一直在做的結果,

我接受所有的HTML標籤中的電子郵件,(從DIV #resultKeeper) 我期待將其刪除,但如何?如果有人能夠強調我,那將是美好的!

這是我收到的電子郵件:

From: name 
Message: message 
Results: 
<div id=\"questionanswrs\"> Question 1 is true</div><div id=\"questionanswrs\"> Question 2 is false</div><div id=\"questionanswrs\"> Question 3 is true</div><div id=\"questionanswrs\"> Question 4 is false</div><div id=\"questionanswrs\"> Question 5 is false</div><div class=\"totalScore\"><br>Your total score is 2/5</div><div class=\"totalScoreok\"><br>CONGRATULATION, YOUR LEVEL IS A1.1</div> 

這裏是jQuery的部分:

$(function() { 
$('#quesForm').on('submit',function(e) { 
e.preventDefault(); 
// I am fetching the form values you could get them by other selectors too 
var uname = $("input[name=username]").val(); 
var uemail = $("input[name=email]").val(); 
var msg = $("textarea").val() 
$.post('submit.php',{username:uname,email:uemail,message:msg,results:$('#resultKeeper').html(),subject:'Subject of your e-mail'},function(result){ 
     // result variable contains your response text 
     // I guess you trying to update your response 
    // notice I have used html(result) as you have just used html() 
     $('#responseMessage').html(result); 

}); 
    // you dont require `return false` 
    // you have already did it using e.preventDefault(); 
}); 
}); 

和我的PHP:

<?php $name = $_POST['username']; 
    $email = $_POST['email']; 
    $message = $_POST['message']; 
    $results = $_POST['results']; 
    $formcontent="From: $name \n Message: $message \n Results: \n $results"; 
    $recipient = "[email protected]"; 
    $subject = "my subject"; 
    $mailheader = "From: $email \r\n"; 
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
    echo "Your email has been send, thank you"; 
    ?> 

謝謝你做的一切!

回答

0

您可以使用strip_tags() php函數嘗試返回一個字符串,其中包含從給定字符串中剝離的所有NULL字節,HTML和PHP標記。

REF:http://in3.php.net/strip_tags

0

嘗試這個

$message = strip_tags($_POST['message']); 
+0

似乎沒有工作... :( – tibewww

+0

試圖剝離標籤後描繪出$消息的價值..檢查是否有仍然是一些標籤 –

+0

我得到了它$結果= strip_tags($結果);//添加此刪除html標籤和所有 乾杯 – tibewww