• Resolved zsatt89

    (@zsatt89)


    First of all, many thanks for the amazing work on the plugin!

    I have set up an ‘Email’ action on one of my ‘Forms’. I am using a custom HTML for this email. For some reason, a bunch of extra <p> tags are being added after the email is sent out, which adds a bunch of extra space on the email itself

    https://ibb.co/BKh9GkC

    Any ideas on how to fix this?

    Thanks!

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

    (@hwk-fr)

    Hello,

    Thanks for the feedback! The problem come from the filters that are added to the WYSIWYG editor during the output. ACF & WordPress add a bunch of filter on it, like wpautop (automatic <p></p> tags), wptexturize, do_shortcode etc…

    in your case, if you send complex HTML emails, you should probably disable them. To do so, you can directly alter the “Email Action” arguments using the following filter:

    
    add_filter('acfe/form/submit/email_args/form=form', 'my_form_email_args', 10, 4);
    function my_form_email_args($args, $form, $action){
        
        /**
         * $args = array(
         *     'from'          => '[email protected]',
         *     'reply_to'      => '[email protected]',
         *     'to'            => '[email protected]',
         *     'cc'            => '[email protected]',
         *     'bcc'           => '[email protected]',
         *     'subject'       => 'Subject',
         *     'content'       => 'Content',
         *     'headers'       => array(
         *         'From: [email protected]',
         *         'Reply-to: [email protected]',
         *         'Cc: [email protected]',
         *         'Bcc: [email protected]',
         *         'Content-Type: text/html',
         *         'charset=UTF-8'
         *     ),
         *     'attachments'   => array(
         *         '/path/to/file.jpg'
         *     )
         * );
         */
        
        // Start buffer
        ob_start();
        
        ?>
        <table>
            <tr>
                <!-- Retrive my_field user input -->
                <td>Field: <?php echo get_field('my_field'); ?></td>
                
                <!-- Retrive my_field from DB -->
                <td>Field DB: <?php echo get_field('my_field', 123); ?></td>
                
                <!-- Retrive query_var from an another action -->
                <td>Query Var: <?php echo get_query_var('my-query-var'); ?></td>
                
            </tr>
        </table>
        <?php
        
        // Retrive buffer
        $content = ob_get_clean();
        
        // Override content
        $args['content'] = $content;
        
        // OR:
        // Retrive the WYSIWYG content, but without filters added by WP/ACF
        $content = get_sub_field('acfe_form_email_content', false);
        
        // Map template tags set in the WYSIWYG field: {fields}, {field:my_field} etc...
        $content = acfe_form_map_field_value($content, 0, $form);
        
        $args['content'] = $content;
        
        /**
         * Return arguments
         * Note: Return false will stop e-mail from being sent
         */
        return $args;
        
    }
    

    Note there’s two solutions in this code. You can decide to override the content, and write your own PHP/HTML code directly there, without using the WYSIWYG (maybe that’s an easier solution for you). Or, you can use the WYSIWYG field content, but without the filters.

    Hope it helps!

    Have a nice day.

    Regards.

Viewing 1 replies (of 1 total)

The topic ‘HTML Email Formatting’ is closed to new replies.