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.
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).
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: