title: Filter/sanitizing email subject and body in PHP
body: <p>I'm using PHPMailer to send emails.</p>
  
  <p>Now, we all know we need to always check user input.<br>
  But how about the subject and body of emails? (so i do not mean the emailadress)</p>
  
  <p>What does need to be sanitized and how to do it? What are the (major) vulnerability's?</p>
  
  <p>Should i'll use something like HTMLPurifier for this? Because i want the user to be able to markup there emails. Or should i'll use/write a BB-code function what can be used?</p>
  
  <p><b>Update:</b></p>
  
  <p><i>For mail body:</i><br>
  I now use htmlspecialchars with ent_quotes flag on. After this ill run a BB-code (jBBCode) parser over the message. This one looks safe now.</p>
  
  <p><i>For subject:</i><br>
  I do not use any validation/sanitizing/etc. (exept min and max strlen) on the subject field.
  Tested with some javascript but it looks like it's all okay. </p>
  
  <p>Can i assume this is safe now? (P.s. the code does not get printed anywhere else than in the email.)</p>