Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert RalfAlbert/mailtest.php
Last active Dec 17, 2015

Embed
What would you like to do?
Test WordPress' is_email() and sanitize_email() functions
<?php
// require wordpress
/**
* @see http://en.wikipedia.org/wiki/Email_address
*/
$email = array();
$email[] = 'john.smith(commentedemail)@example.com';
$email[] = '(commentedemail)john.smith@example.com';
$email[] = 'john.smith@(commentedemail)example.com';
$email[] = 'john.smith@example.com(commentedemail)';
$email[] = 'john.smith(commented email)@example.com';
$email[] = '(commented email)john.smith@example.com';
$email[] = 'john.smith@(commented email)example.com';
$email[] = 'john.smith@example.com(commented email)';
array_walk(
$email,
function($e){ printf('%s -> %s / %s<br>',$e, true==is_email($e)?'yes':'no', sanitize_email($e) ); }
);
/*
* Output
*/
/*
john.smith(commentedemail)@example.com -> no / john.smithcommentedemail@example.com
(commentedemail)john.smith@example.com -> no / commentedemailjohn.smith@example.com
john.smith@(commentedemail)example.com -> no / john.smith@commentedemailexample.com
john.smith@example.com(commentedemail) -> no / john.smith@example.comcommentedemail
john.smith(commented email)@example.com -> no / john.smithcommentedemail@example.com
(commented email)john.smith@example.com -> no / commentedemailjohn.smith@example.com
john.smith@(commented email)example.com -> no / john.smith@commentedemailexample.com
john.smith@example.com(commented email) -> no / john.smith@example.comcommentedemail
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.