Filter wp_mail to Append Current Post Title to Message


I’m looking for a way to append the wp_mail() $args[message] with the title of the ‘current’ post so that in practice my form will include a “Sent via [post_title]” at the end of the enquiry. I’ve tried the following but I guess that by the time wp_mail() fires the $post object has been left behind.

function append_wp_mail( $args ) {

    global $post;

    $args['message'] .= '<br><br>Sent from ' . $post->ID;

    return $args;
add_filter( 'wp_mail', 'append_wp_mail' );

How can I access the $post object when filtering wp_mail()?

Kevin Nugent 4 months 0 Answers 14 views 0

Leave an answer