We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m using the MODx mail service to send via SMTP ($modx->mail->send()) and ran across an error that’s making me crazy.

    Normal mail goes through fine, but if I use an odd email address for the "from" (e.g. [email protected]) the send fails. I’d like to know where the failure is occurring but can’t seem to get any error info -- I just get a false return from send(). PHPMailer sets an ErrorInfo variable but I can’t find any way of getting at it and there’s nothing in the MODx error log.

    That email address passes extensive email validation checks and I don’t know why whatever is throwing the error cares what the return address is. I know it’s a trivial problem but it bugs me that I can’t get to the bottom of it.

    Is there a way to get at the ErrorInfo contents? If not, possibly there should be. I’ve tried all the obvious ways I could think of.

      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 3749
      • 24,544 Posts
      To answer my own questions, the error info is all available once you figure it out.

      Note that this applies to MODx Revolution.

      This will give you the error info. It’s not as helpful as it might be because SMTP errors are not put into the ErrorInfo variable, but you do find out that the "From" field caused the failure. You also get a lexicon failure because the mailer still has the old-style language files.

      echo $this->modx->mail->mailer->ErrorInfo;



      To get more info, I worked this out:
      function _my_mail(blah, blah, blah) {
      
      /* set up for mailing code deleted */
      
      /*  send  */
      
          if (!$this->modx->mail->send()) {
      
              /* if debug is on, resend with error reporting */
              if($this->debug) {
                  if ($this->use_SMTP) {
                      echo "<b>SMTP errors:</b><br />";
                      $this->modx->mail->mailer->SMTPDebug = 2;
                      $this->modx->mail->send();
                  }
                  echo '<br /><br /><b>' . "Mailer ErrorInfo:</b><br />";
                  die($this->modx->mail->mailer->ErrorInfo);
              }
      
              die('<b>' . $this->modx->lexicon('mail-failure') . '</b>');
      
          }
          $this->modx->mail->reset();
      }


      This gets you very detailed information on the failure (if you want even more -- too much usually --, you can set SMTPDebug = 4).

      For the curious, [email protected] manages to sneak by almost all good validation code because of the exception for two-letter country code domains. In my case, the remote SMTP host flagged it as a bad domain and refused to send the mail, either because it’s not legal or because it doesn’t exists -- not sure which.

      I’m not sure what would happen with mail() as opposed to SMTP becuase I don’t have Revolution installed anywhere with mail() working. I did try sending from an 0.9.6 site using mail() and that return email appeared to work fine but the mail never arrived, so I imagine it’s the same.

      [Update] The messages are actually sent when using mail() -- at least in 0.9.6 -- they just go into the trash if you previously set a filter a long time ago to put them there and then forgot you did that. embarrassed

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting