2

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'grady@hotmail.com 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
2

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.

4
  • A better check would be return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email); Source – user40422 May 21 '15 at 13:40
  • @Bondye I wrote this especially to allow me the use of my local addresses. – fuxia May 21 '15 at 13:41
  • Ok, sorry for the misunderstanding. Maybe rename the function to check_mail_local ;) – user40422 May 21 '15 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, the class-phpmailer.php class ;-) – birgire May 21 '15 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.