如何从$ post中删除html标签到电子邮件?

时间:2014-01-08 18:15:32

标签: php jquery html strip

当我收到我一直在做的在线测验的结果时,

我收到了电子邮件中的所有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@mail.com";
   $subject = "my subject";
   $mailheader = "From: $email \r\n";
   mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
   echo "Your email has been send, thank you";
  ?>

谢谢你的一切!!

2 个答案:

答案 0 :(得分:0)

您可以使用strip_tags() php函数尝试返回一个字符串,其中包含从给定字符串中剥离的所有NULL字节,HTML和PHP标记。

参考: http://in3.php.net/strip_tags

答案 1 :(得分:0)

试试这个

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