• Is there a way to change the content type for only the password reset email?

    I have a custom HTML template for it, and have set wp_mail_content_type to text/html and am applying the template with a filter on retrieve_password_message. That all works fine and I get an HTML email for it, but I’m having a hard time figuring out where/how to reset wp_mail_content_type since I’m not actually calling wp_mail() anywhere.

    Any help would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The filter to manage content type is ‘wp_mail_content_type’. You could add this filter to set the next email to the desired type from another callback used exclusively by the lost password process, ‘retrieve_password_message’ for example. You don’t need to actually change the message, just return the passed message unchanged. You are using this filter like an action hook because it only fires for password resets and it fires before the ‘wp_mail_content_type’ filter.

    Thread Starter jmock

    (@jmock)

    I don’t think I follow. I’m using wp_mail_content_type to set it like so:

    
    function xxx_wp_email_content_type() {
    	return 'text/html';
    }
    add_filter( 'wp_mail_content_type', 'xxx_wp_email_content_type' );
    

    And I have another function that changes the content of the email:

    
    function xxx_wp_retrieve_password_message( $content, $key ) {
    	ob_start();
    	
    	$email_subject = xxx_wp_retrieve_password_title();
    	
    	include( 'templates/email_header.php' );
    	include( 'templates/lost_password_email.php' );
    	include( 'templates/email_footer.php' );
    	
    	$message = ob_get_contents();
    	ob_end_clean();
    
    	return $message;
    }
    add_filter( 'retrieve_password_message', 'xxx_wp_retrieve_password_message', 10, 2 );
    

    Do you mean I should call xxx_wp_email_content_type() inside xxx_wp_retrieve_password_message()?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set content type to HTML for lost password email only’ is closed to new replies.