Howe to debug FormIt when sending emails

Hi all,
I am receiving log errors from FormIt saying that an email was not sent because it was being considered spam.

i have tried updating the code to include details of the email in the log message so I can work out what the issue is and if it is a specific destination that is blocking my emails.

This is the current error that is appearing in the log.
[2019-08-09 12:35:15] (ERROR @ /public_html/core/components/formit/src/FormIt/Hook/Email.php : 304) [FormIt] An error occurred while trying to send the email. To:1 Subject:1 SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: This message was classified as SPAM and may not be delivered
SMTP code: 550

I have changed the core/components/formit/src/FormIt/Hook/Email.php file to add some detail, but as you can see from above, I am not getting the actual email address or subject. just the array position.

    if (!$sent) {
        $this->hook->errors[] = $this->modx->lexicon('formit.email_not_sent').' '.print_r($this->modx->mail->mailer->ErrorInfo, true);
    /*  Changed from  print_r($emailTo[0])  to print_r($emailTo)      */ 
        $this->modx->log(\modX::LOG_LEVEL_ERROR, '[FormIt] '.$this->modx->lexicon('formit.email_not_sent').' To:'.print_r($emailTo).' Subject:'.print_r($subject).' '.print_r($this->modx->mail->mailer->ErrorInfo, true));

    return $sent;

Can anyone help with what I should be using to get the recipient and subject of the email.
To:’.print_r($emailTo).’ Subject:’.print_r($subject).’

or, any suggestions on how to get better visibility of audit details of the email.

thanks in advance.

Is the web server sending email from the same IP address as the mail server for the domain? If not you may be running into problems with SPF being enabled by servers at the other end. If this is a possibility you might need to set up a spf txt record

A couple more thoughts:

Make sure the from address matches email sender.
Make sure you have a reply-to address.
Make sure the sender is authorized to send email from your server.

I got tired of messing with this stuff, so I send almost all messages through Mailgun. It was a pain to set up (you have to set the SPF record Andy mentioned and also a DKIM record), but it’s free for (IIRC) 10,000 messages/month – and I get much better deliverability.

If you have PHP coding skills, you can look at the code of the Notify extra – specifically the MailService class and the MailgunX class (which is also an extra).

1 Like

Thanks for the suggestions, but i was wanting to know how I could return the email address from the array for the log.

@bobray, do you substitute the smtp details for mailgun, or have you converted to use the API calls.

When used with the Mailgun option, Notify talks directly to the Mailgun API, using the MailgunX class and Guzzle6.

Thanks for that! I will check them out.

When using print_r, you should provide the second parameter as true to indicate you want to return the value. And as $subject is a string (at least I assume it is), you can just add that directly. Like this:

To:' . print_r($emailTo, true) . ' Subject: ' . $subject