How to call shortcode in mail body wordpress

To call a shortcode in the body of an email sent from WordPress, you can use the do_shortcode function. Here are a few ways to do it:

Method 1: Using do_shortcode in your theme's functions.php file

You can add the following code to your theme's functions.php file:

function send_email_with_shortcode() {
    $to = '[email protected]';
    $subject = 'Test Email with Shortcode';
    $body = do_shortcode('[your_shortcode]');
    wp_mail($to, $subject, $body);
}

Replace [your_shortcode] with the actual shortcode you want to use.

Method 2: Using do_shortcode in your plugin's code

If you're creating a plugin, you can use the do_shortcode function in your plugin's code. For example:

function my_plugin_send_email() {
    $to = '[email protected]';
    $subject = 'Test Email with Shortcode';
    $body = do_shortcode('[your_shortcode]');
    wp_mail($to, $subject, $body);
}

Method 3: Using a third-party plugin

There are several plugins available that allow you to send emails with shortcodes, such as WP Email Templates or Email Templates. These plugins provide a more user-friendly interface for creating and sending emails with shortcodes.

Tips and considerations