I'm trying to send an invitation to someone to become a user of a private Wordpress blog, but WP apparently doesn't accept an apostrophe appearing in the name in the email address as valid. For example, it seems it would consider maryo'[email protected] as an invalid email address, because of the apostrophe in Mary's surname. Has anyone else had this problem, and is there a way around it, by substituting a different character in place of the apostrophe?
1 Answer
Filter is_email
and sanitize_email
, then apply a better check:
namespace Wpse\Email;
add_filter( 'is_email', __NAMESPACE__ . '\check_mail_address', 10, 2 );
add_filter( 'sanitize_email', __NAMESPACE__ . '\check_mail_address', 10, 2 );
function check_mail_address( $result, $email )
{
return filter_var( $email, FILTER_VALIDATE_EMAIL );
}
The PHP function is still not RFC 5321 compliant, but better than the WordPress check.
-
A better check would be
return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email);
Source– user40422May 21, 2015 at 13:40 -
@Bondye I wrote this especially to allow me the use of my local addresses.– fuxia ♦May 21, 2015 at 13:41
-
Ok, sorry for the misunderstanding. Maybe rename the function to check_mail_local ;)– user40422May 21, 2015 at 13:43
-
nice and short (I thought WordPress would never include a code with the PHP
filter_*
functions, so I was surprised to find it in one place, theclass-phpmailer.php
class ;-)– birgireMay 21, 2015 at 14:17