1

I'm using a Znarkus Postmark PHP class to handle mailer.

POST RESPONSE:

{"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":[]}

Recently my custom validator is working, but now the POST request status is having a 500 internal server error.

{"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":[]}

I discovered that it's failing in the email validator snippet:

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;
    }

I'm quite confident that my regex was working before. But then, all of my mailers started to fail.

rukia_kuchiki_21
  • 1,279
  • 3
  • 17
  • 34
  • Take a look at your exception: `Reply To address \"1\" is invalid` - you seem to be passing `1` into `replyTo()` - that is, indeed, not a valid e-mail address, and the validator is rightfully rejecting it. The error happens somewhere *before* this code executes. – Piskvor left the building Apr 04 '14 at 11:28
  • My test email address is valid. Sample: `xiruken@gmail.com` . Commenting out the validator, gives me a successful response. But, I can't just leave it like that. – rukia_kuchiki_21 Apr 04 '14 at 11:30
  • The test address `"xiruken@gmail.com"` is valid, but, somewhere along the way, your code __changes__ it to `"1"` - at the first line of your code snippet, the content of `$address` is already `1`, and that is not a valid e-mail address; the validator just catches on to that. – Piskvor left the building Apr 04 '14 at 11:31
  • From the same stack trace that *you* have posted: `Stack trace:\n#0 \/var\/www\/stm\/lib\/croscon\/stm\/Email.php(59): Postmark\\Mail->replyTo(true, 'customerservice...')` - see? You're passing in `true` instead of your test address. – Piskvor left the building Apr 04 '14 at 11:34
  • Ok maybe it's about how I pass the parameters. Sorry you don't have to be so heavy for a beginner like me. Thanks btw. And you guys don't have to put `(-)` vote for my question if I posted my question politely. And if I tried a thing or two. Blame me if I didn't put some codes and if I just asked for the complete regex validator. Lol. – rukia_kuchiki_21 Apr 04 '14 at 11:35
  • You're welcome. I have been too blunt; for this I apologize. However, *please*, next time read the exception and stack trace generated, before you copy-paste it here and say "validator complains, therefore validator's fault." Also, you have a point with the downvote; reversing. – Piskvor left the building Apr 04 '14 at 11:39
  • 1
    Oh, btw: one more tip which has helped me a lot: when something breaks, check the version control to see what has changed recently; this helps me to find a lot of new bugs/regressions quickly. – Piskvor left the building Apr 04 '14 at 11:55
  • It might be better to use Postmark's email validation from the API directly to make sure the regex matches. We use as loose a validation as we can but if you're validating the address on your side first, it may not necessarily match up with the Postmark validation. You can always try the request as the validation step and then re queue it up if it fails or report it as needed. Just a suggestion :) – JP Toto Apr 04 '14 at 14:24

0 Answers0