Skip to content

Commit

Permalink
More robust handling of pattern selection value in validateAddress, f…
Browse files Browse the repository at this point in the history
…ixes PHPMailer#226

Fix HTML5 email validation
  • Loading branch information
Synchro committed May 2, 2014
1 parent 463cc29 commit e6d7f38
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions class.phpmailer.php
Expand Up @@ -858,11 +858,8 @@ public function getLastMessageID()
*/
public static function validateAddress($address, $patternselect = 'auto')
{
if ($patternselect == 'auto') {
if (defined(
'PCRE_VERSION'
)
) { //Check this constant so it works when extension_loaded() is disabled
if (!$patternselect or $patternselect == 'auto') {
if (defined('PCRE_VERSION')) { //Check this constant so it works when extension_loaded() is disabled
if (version_compare(PCRE_VERSION, '8.0') >= 0) {
$patternselect = 'pcre8';
} else {
Expand Down Expand Up @@ -919,8 +916,8 @@ public static function validateAddress($address, $patternselect = 'auto')
* This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
* @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
*/
return '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])'.
'?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD';
return (bool)preg_match('/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
'[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $address);
break;
case 'php':
default:
Expand Down Expand Up @@ -1776,8 +1773,8 @@ public function getMailMIME()
/**
* Returns the whole MIME message.
* Includes complete headers and body.
* Only valid post PreSend().
* @see PHPMailer::PreSend()
* Only valid post preSend().
* @see PHPMailer::preSend()
* @access public
* @return string
*/
Expand Down

0 comments on commit e6d7f38

Please sign in to comment.