• zlatimuud

    (@zlatimuud)


    Hi SureMail team,

    I’m following up regarding the Reply-To snippet you previously provided:

    add_filter( 'wp_mail', function( $atts ) {
        // Add reply-to header if not already present
        if ( ! empty( $atts['headers'] ) ) {
            $headers = is_array( $atts['headers'] ) ? $atts['headers'] : explode( "\n", $atts['headers'] );
    
            // Check if reply-to already exists
            $has_reply_to = false;
            foreach ( $headers as $header ) {
                if ( stripos( $header, 'reply-to' ) !== false ) {
                    $has_reply_to = true;
                    break;
                }
            }
    
            if ( ! $has_reply_to ) {
                $headers[] = 'Reply-To: Your Name <replies@example.com>';
                $atts['headers'] = $headers;
            }
        }
    
        return $atts;
    } );
    

    We are currently troubleshooting an Apple DKIM body hash verification failure, and MailChannels (Hostinger’s relay) reviewed the situation.

    They said that the snippet is not necessarily directly causing the DKIM body hash failure, since Reply-To is a header and the error concerns the DKIM body hash (bh=). However, they pointed out that the way the snippet handles the headers could potentially introduce line-ending inconsistencies.

    Specifically, they highlighted this line:

    explode( "\n", $atts['headers'] )
    

    Their concern is that if $atts['headers'] contains CRLF (\r\n) line endings, splitting only on \n can leave trailing \r characters in individual headers. Depending on how WordPress/PHPMailer subsequently rebuilds the message, this could potentially result in inconsistent LF/CRLF handling.

    MailChannels also suggested forcing SMTP-standard CRLF line endings and quoted-printable encoding through phpmailer_init:

    add_action( 'phpmailer_init', function( $phpmailer ) {
        $phpmailer->LE = "\r\n";
        $phpmailer->Encoding = 'quoted-printable';
    } );
    

    Could you please review the Reply-To snippet you provided and confirm whether its handling of $atts['headers'] is safe?

    In particular:

    • Could explode( "\n", $atts['headers'] ) leave stray \r characters or otherwise affect PHPMailer message formatting?
    • Would you recommend normalizing the headers before converting them to an array?
    • Is there a safer SureMail-compatible way to add Reply-To without modifying the raw wp_mail headers in this manner?
    • Do you see any conflict with setting $phpmailer->LE = "\r\n" and $phpmailer->Encoding = 'quoted-printable' via phpmailer_init?
    • Ideally, could you provide a corrected version of the Reply-To snippet that preserves proper CRLF handling?

    We’re trying to eliminate anything at the WordPress/SureMail level that could alter the message after the DKIM body is generated or cause inconsistent message canonicalization.

    Thanks!

You must be logged in to reply to this topic.