Skip to content

Commit 678cf34

Browse files
committed
Fix mismatch between Q2A and PHPMailer email validation algorithm
1 parent 7ed3f6a commit 678cf34

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

qa-include/app/emails.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function qa_send_email($params)
135135

136136
require_once QA_INCLUDE_DIR . 'vendor/PHPMailer/PHPMailerAutoload.php';
137137

138+
PHPMailer::$validator = 'php';
138139
$mailer = new PHPMailer();
139140
$mailer->CharSet = 'utf-8';
140141

qa-include/util/string.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ function qa_email_validate($email)
736736
{
737737
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
738738

739-
return preg_match("/^[\-\!\#\$\%\&\'\*\+\/\=\?\_\`\{\|\}\~a-zA-Z0-9\.\^]+\@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\.\-]+$/", $email) === 1;
739+
return (bool)filter_var($email, FILTER_VALIDATE_EMAIL);
740740
}
741741

742742

qa-tests/UtilStringTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ public function test__qa_email_validate()
126126
$goodEmails = array(
127127
'hello@example.com',
128128
'q.a@question2answer.org',
129-
'example@newdomain.app'
129+
'example@newdomain.app',
130130
);
131131
$badEmails = array(
132132
'nobody@nowhere',
133133
'pokémon@example.com',
134134
'email @ with spaces',
135135
'some random string',
136+
'dotbeforeat.@email.com',
136137
);
137138

138139
foreach ($goodEmails as $email) {

0 commit comments

Comments
 (0)