Send mail subject line converts html entities to charecters


Many of us might have encountered this issue, seems small but creates major impact. Both Php and WordPress send mail
method will converts subject line’s html entities such as (single quotes), ( double quotes ), ( @ ), ( ! )…. into characters while sending mail.

I got solution for this issue, I used html_entity_decode() function to get rid off this issue.

    
       wp_mail( $to, stripslashes_deep( html_entity_decode( $subject, ENT_QUOTES, 'UTF-8' ) ), $message );
    

Parameters Description:
Returns a string with backslashes stripped off. (\’ becomes ‘ and so on.) Double backslashes (\\) are made into a single backslash (\).

UTF-8: Defines character set ENT_QUOTES will converts both double and single quotes.

Join the Conversation

2 Comments

  1. This is awesome, Thanks a lot Sandeep for writing this Post.

    Thankyou once again and keep writing good posts like this.

Leave a comment