• Resolved publicradio

    (@publicradio)


    I’m troubleshooting why emails that come through my ACFE forms get marked as spam, and one issue is that they’re all sent with content type text/html, but the body isn’t wrapped in an HTML tag.

    I don’t need to send HTML emails, so I’m fine just changing the header from text/html to text/plain. However, I can’t get the submit_email_args hook to work. I’ve tried:

    add_filter('acfe/form/submit_email_args', function($args, $form, $action){
    $args['headers'] = str_replace('text/html', 'text/plain', $args['headers']);
    $args['subject'] = 'Changed subject';
    return $args;
    }, 10, 3);

    And I’ve tried

    add_filter('acfe/form/submit_form', function($form, $action){
    $email = $action['email'];
    $email['subject'] = 'New subject';
    return $action;
    }, 10, 2);

    Not only can I not get the headers to change, but even the subject line won’t change with this code in place. I don’t actually need to change the subject line, but I was trying to see if this was firing at all (it isn’t).

    If someone can help me with the specific issue of the filter not firing, that would be great. But really, the larger issue is that everything is being sent as HTML emails, yet the body is not wrapped in an HTML tag. Maybe that’s more of a bug and I should open an issue about it in github, I don’t know.

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    The hook acfe/form/submit_email_args is the correct fitler to do such operation.

    Regarding the subject change:

    Your code is correct and will override all emails subject. Please note that ACFE Form Email Action use wp_mail() behind the scene (see documentation). Which means the email & the subject can be also overwritten by another WP hook or third party plugin, even if the ACFE Form hook is correct.

    I would recommend to check that you don’t have another hooks related to mails, or plugins if it still doesn’t work. In all case, you can test it on a blank WP Install, and you’ll see it working.

    add_filter('acfe/form/submit_email_args', function($args, $form, $action){

    $args['subject'] = 'Changed subject';
    return $args;

    }, 10, 3);

    Regarding the content type change:

    Please note the headers array is sequential array, as described in the documentation. Which means that you have to get the headers array key (numerical) to overwrite it. Here is a usage example using the same hook:

    add_filter('acfe/form/submit_email_args', function($args, $form, $action){

    // get headers content type key
    $content_type_key = array_search('Content-Type: text/html', $args['headers']);
    if($content_type_key !== false){
    $args['headers'][ $content_type_key ] = 'Content-Type: text/plain'; // replace to plaintext
    }

    return $args;

    }, 10, 3);

    Some small note about email deliverability: Email sent as text/html without actual <html> tag shouldn’t trigger it as spam. Your email deliverability issue is most likely related to the service that send the email (SMTP or your own server), and the configuration of your DNS records, such as SPF/DKIM. I would recommend to take a look at these in your case.

    Hope it helps!

    Regards.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.