Can I send any other emails in my own styling ?

Yes you can. This will require some custom coding on your end.

You will need to create a function which is called when a certain action is performed or a hook is 'reached'.

You need to make use of the wp_mail() function, which is a WordPress action.

Example

  1. function b3_custom_mail_function( $to ) {
  2.     $to             = 'email@recipient.com'; 
  3.     $from_name      = 'Dummy'; 
  4.     $from_email     = 'Dummy';
  5.     $subject        = __( 'Your subject', 'your-textdomain' );
  6.     $custom_message = __( 'Your own message', 'your-textdomain' );
  7.     $custom_message = b3_replace_template_styling( $custom_message );
  8.     $custom_message = strtr( $custom_message, b3_replace_email_vars( [] ) );
  9.     $custom_message = htmlspecialchars_decode( stripslashes( $custom_message ) );
  10.  
  11.     $headers = array(
  12.         'From: ' . $from_name . ' <' . $from_email . '>',
  13.         'Content-Type: text/html; charset=UTF-8',
  14.     );
  15.     wp_mail( $to, $subject, $custom_message, $headers );
  16. }

Note

As you can see 2 values are defined as 'Dummy'. Why is this ? Because we're using a filter which overrides the sender name and sender email, just before the email is sent, to make sure you always have the correct sender name and email (to avoid spam).

Tags