Email validation regular expression

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
ganchiku
Forum Newbie
Posts: 2
Joined: Sun Dec 28, 2008 11:59 pm

Email validation regular expression

Post by ganchiku »

Hello,

I was developing a web site to send email to Japanese mobile phone user. Because of their selfish discipline, the major two mobile service phone companies do not follow RFC.
They accept ridiculous addresses such as:
foobar..@example.com

and some of our users have such addresses. :(

This is big trouble for developers in Japan, because web service for mobile phone users is big market.
If I passed the above address to send method of swift class, it throws exception that explain the address is wrong. I know it is wrong, but I have to send to the address anyhow.
To avoid this problem, one of our solution is doublequotating the wrong dot-atom part as follows:
"foobar.."@example.com

If I could do this, I can send the mail to the address and the rule follows RFC.
So, I wonder if developers of Swift Mailer can fix the Swift_Message_Encoder::CHEAP_ADDRESS_RE value as:

const CHEAP_ADDRESS_RE = '(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|"[^\\\\\x80-\xff\n\015"]*(?:\\\\[^\x80-\xff][^\\\\\x80-\xff\n\015"]*)*")(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|"[^\\\\\x80-\xff\n\015"]*(?:\\\\[^\x80-\xff][^\\\\\x80-\xff\n\015"]*)*"))*@(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[^\x80-\xff])*\])(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[^\x80-\xff])*\]))*'

Because symfony is good combination with Swift Mailer, I would like to use Swift, but with rejecting some mail address as I showed above, many developers in Japan have to give up using Swift Mailer.

Thanks,
Shin
ganchiku
Forum Newbie
Posts: 2
Joined: Sun Dec 28, 2008 11:59 pm

Re: Email validation regular expression

Post by ganchiku »

I solved this problem.

I was passing $recipients parameter as string, so there was validator, but when I passed an object of Swift_RecipientList, it works!

Because Swift_Recipients class is a subclass of Swift_AddressContainer, it go through the email validation! Well, I don't know if this is right solution, but as long as it works, I',m happy.

Thank you for your time.

Shin
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Email validation regular expression

Post by Chris Corbyn »

The whole way recipients are specified has been greatly improved in version 4. Feel free to check out the beta (linked to in an announcement at the top this sub-forum).
Post Reply