WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/sanitize email

Description

Strips out all characters that are not allowable in an email address.

After sanitize_email() has done its work, it passes the sanitized e-mail address through the sanitize_email filter.

Usage

<?php sanitize_email$email ?>

Parameters

$email
(string) (required) Email address to filter.
Default: None

Return Values

(string) 
Filtered email address.

Examples

<?php
$sanitized_email = sanitize_email('     admin@example.com!     ');
echo $sanitized_email; // will output: 'admin@example.com'
?>

Notes

  • This function uses a smaller allowable character set than the set defined by RFC 5322. Some legal email addresses may be changed.
  • Allowed character regular expression: /[^a-z0-9+_.@-]/i.

Change Log

Since: 1.5.0

Source File

sanitize_email() is located in wp-includes/formatting.php.

Related

Functions

sanitize_email() is in a class of functions that help you sanitize potentially unsafe data which allow you to pass an arbitrary variable and receive the clean version based on data type. Others include:

Filters

See also index of Function Reference and index of Template Tags.