PHP Code Snippet - Check Email Headers

PHP Code Snippet - Check Email Headers

PHP Code Snippet - Check Email Headers

PHP code snippet to check email headers in a string. NoEmailHeaders function checks given string. Function return TRUE if there are no email headers in given string, if not function will return FALSE.

Bookmark:

PHP Code Snippet - Check Email Headers

This PHP code snippet makes sure there is no email headers in given string. This function uses regular expression to match string pattern to check for email headers. These code snippets useful to block spammers/hackers attempt to pass malicious data to PHP scripts.

function NoEmailHeaders($text)
{
   return preg_match("/(%0A|%0D|\\n+|\\r+)(content-type:|to:|cc:|bcc:)/i", $text) == 0;
}


PHP Keywords Used:

  • preg_match

Code Snippet Information:

  • Applies To: PHP, Spammers/Hackers Blocking, Regular Expression
  • Programming Language : PHP

External Resources:

Leave a comment