Support » Plugin: Password Reset with Code for WordPress REST API » “bdpwr_code_email_text” Filter with HTML

  • Resolved kdias


    Hello !

    First of all, thanks for this plugin, it’s incredibly usefull !

    I have a little question though, concerning the content custom filter.

    Is it possible to custom the visual aspect of the message, with HTML.

    I tried to do this :

    add_filter( 'bdpwr_code_email_text' , function( $text , $email , $code , $expiry ) {
        $text = "Password reset has been requested for the following email :  " . $email .". Your reset password :  " . $code . ". \n will expire at " . bdpwr_get_formatted_date( $expiry ) . ".";
            <h1>Password reset</h1>
            <p><?php echo $text ?></p>
        $html = ob_get_clean();
        return html_entity_decode($html);
    }, 10 , 4 );

    But all the HTML tags render as a string. Do you have any idea how to make this work ?

    Thanks a lot !


Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author dominic_ks



    Thanks for the feedback, and glad you are finding it useful.

    Yes this is likely happening because by default WordPress sends emails as plain text and you need to set the Content-Type header for emails to be “text/html; charset=UTF-8”

    I usually do this with a filter like this, NB. this is pure WordPress and not specific to this plugin:

     * Filter all emails to adjust the headers
     * @param array $args wp_mail arguments
     * @return array updated wp_mail arguments
    function my_mail_filter( $args ) {
      //if headers already exist but not as an array, change it to be an array to allow additional headers
      if( isset( $args['headers'] ) && ! is_array( $args['headers'] ) ) {
        $existing_headers = $args['headers'];
        unset( $args['headers'] );
        $args['headers'][] = $existing_headers;
      $args['headers'][] = 'Content-Type: text/html; charset=UTF-8';
      return $args;
    add_filter( 'wp_mail' , 'my_mail_filter' );

    Hope that helps and let me know if it works!


    Okay, that’s just amazing.

    Thank’s a lot for your help !

    Plugin Author dominic_ks


    No problem, I’ll make this as resolved then.

    If you have a spare moment and wouldn’t mind leaving a review for the plugin it’d be much appreciated:

    Have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.