Znarkus邮戳PHP中的电子邮件地址验证程序
我使用一个Znarkus邮戳PHP类来处理mailer 回复后:Znarkus邮戳PHP中的电子邮件地址验证程序,php,regex,postmark,Php,Regex,Postmark,我使用一个Znarkus邮戳PHP类来处理mailer 回复后: {"status":false,"validator":null,"response":true,"errors":[],"exception":"exception 'InvalidArgumentException' with message 'Reply To address \"1\" is invalid' in \/var\/www\/stm\/vendor\/znarkus\/postmark\/src\/Postm
{"status":false,"validator":null,"response":true,"errors":[],"exception":"exception 'InvalidArgumentException' with message 'Reply To address \"1\" is invalid' in \/var\/www\/stm\/vendor\/znarkus\/postmark\/src\/Postmark\/Mail.php:276\nStack trace:\n#0 \/var\/www\/stm\/lib\/croscon\/stm\/Email.php(59): Postmark\\Mail->replyTo(true, 'customerservice...')\n#1 \/var\/www\/stm\/lib\/croscon\/stm\/Email.php(119): croscon\\stm\\Email->sendMeWithKnownEmail('contactUs', 'info@muserk.com', ' has contacted ...', Array, 'customerservice...', 'customerservice...', true)\n#2 \/var\/www\/stm\/services\/Contact.php(32): croscon\\stm\\Email->contactUs(NULL, NULL, NULL, false)\n#3 [internal function]: App\\Service\\Contact->sendMethod()\n#4 \/var\/www\/stm\/vendor\/croscon\/strongpanda\/StrongPanda\/Service.php(89): call_user_func_array(Array, Array)\n#5 \/var\/www\/stm\/vendor\/croscon\/strongpanda\/StrongPanda\/Service\/Translator\/JSONRPC.php(117): StrongPanda\\Service->run('send')\n#6 \/var\/www\/stm\/vendor\/croscon\/strongpanda\/StrongPanda\/FrontController.php(99): StrongPanda\\Service\\Translator\\JSONRPC->CallService(Object(App\\Service\\Contact), 'send', Array)\n#7 \/var\/www\/stm\/public\/index.php(10): StrongPanda\\FrontController->__construct()\n#8 {main}","messages":[]}
最近,我的自定义验证器正在工作,但现在POST
请求状态有一个500内部服务器错误
{"status":false,"validator":null,"response":true,"errors":[],"exception":"exception 'InvalidArgumentException' with message 'Reply To address \"1\" is invalid' in \/var\/www\/stm\/vendor\/znarkus\/postmark\/src\/Postmark\/Mail.php:276\nStack trace:\n#0 \/var\/www\/stm\/lib\/croscon\/stm\/Email.php(59): Postmark\\Mail->replyTo(true, 'customerservice...')\n#1 \/var\/www\/stm\/lib\/croscon\/stm\/Email.php(119): croscon\\stm\\Email->sendMeWithKnownEmail('contactUs', 'info@muserk.com', ' has contacted ...', Array, 'customerservice...', 'customerservice...', true)\n#2 \/var\/www\/stm\/services\/Contact.php(32): croscon\\stm\\Email->contactUs(NULL)\n#3 [internal function]: App\\Service\\Contact->sendMethod()\n#4 \/var\/www\/stm\/vendor\/croscon\/strongpanda\/StrongPanda\/Service.php(89): call_user_func_array(Array, Array)\n#5 \/var\/www\/stm\/vendor\/croscon\/strongpanda\/StrongPanda\/Service\/Translator\/JSONRPC.php(117): StrongPanda\\Service->run('send')\n#6 \/var\/www\/stm\/vendor\/croscon\/strongpanda\/StrongPanda\/FrontController.php(99): StrongPanda\\Service\\Translator\\JSONRPC->CallService(Object(App\\Service\\Contact), 'send', Array)\n#7 \/var\/www\/stm\/public\/index.php(10): StrongPanda\\FrontController->__construct()\n#8 {main}","messages":[]}
我发现它在电子邮件验证程序片段中失败:
public function &replyTo($address, $name = null)
{
if (!$this->_validateAddress($address)) {
throw new InvalidArgumentException("Reply To address \"{$address}\" is invalid");
}
$this->_replyTo = array('address' => $address, 'name' => $name);
return $this;
}
/**
* Validates an e-mail address
* @param $email
* @return bool
*/
private function _validateAddress($email)
{
// http://php.net/manual/en/function.filter-var.php
// return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
// filter_var proved to be unworthy (passed foo..bar@domain.com as valid),
// and was therefore replace with
$regex = "/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i";
// from http://fightingforalostcause.net/misc/2006/compare-email-regex.php
return preg_match($regex, $email) === 1;
}
我很有信心我的
regex
以前可以工作。但是,我的所有邮件都开始失败。看看你的异常:回复地址“1”无效
-你似乎在将1
传递到replyTo()
-这确实不是一个有效的电子邮件地址,验证程序理所当然地拒绝了它。错误发生在代码执行之前的某个地方。我的测试电子邮件地址有效。示例:xiruken@gmail.com
。注释掉验证器,给了我一个成功的响应。但是,我不能就这样离开。测试地址“xiruken@gmail.com“
是有效的,但是,在过程中的某个地方,您的代码将其更改为“1”
——在代码段的第一行,$address
的内容已经是1
,而这不是有效的电子邮件地址;验证器正好抓住了这一点。从您发布的相同堆栈跟踪:堆栈跟踪:\n\0\/var\/www\/stm\/lib\/croscon\/stm\/Email.php(59):邮戳\\Mail->replyTo(true,'customerservice…')
-看到了吗?您正在传递的是true
而不是您的测试地址。哦,顺便说一句:还有一个技巧对我帮助很大:当出现问题时,检查版本控制以查看最近发生了什么变化;这有助于我快速发现许多新的bug/回归。