Support » Plugin: Advanced Custom Fields » Custom Field in a email message body

  • Resolved Marlimant


    Hi: I’m trying to print a Custom Field in a email message body.
    I have tried with:
    '. get_field('client_name', $post_id).'
    '. the_field('client_name', $post_id).'
    '.do_shortcode( get_field('client_name') ).'
    '.do_shortcode( the_field('client_name', $post_id) ).'
    '.do_shortcode( get_field('client_name', $post_id) ).'
    '.do_shortcode( the_field('client_name') ).'
    Without results.

    This is an example of my code in functions.php

    // Sent email on every post
    function rhk_send_email($id) {
    $post = get_post($id);
    $headers []= "MIME-Version: 1.0\r\n";
    $headers []= "Content-Type: text/html; charset=UTF-8\r\n";
    $headers []= "From: My website <>";
    $headers []= "Reply-To:" ;
    $to = "";
    $subject = "News of my web";
    $message = 
    Dear '. get_field('client_name', $post_id).'
    This is your message.
    wp_mail($to, $subject, $message, $headers); }
    add_action('publish_post', 'rhk_send_email');

    Any help will be welcome!

    • This topic was modified 2 years, 5 months ago by Marlimant.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    It will work with '. get_field('client_name', $post_id).'

    Problem is $post_id does not exist in your snippet, you should use $id instead (if this $id is your post ID)

    Let us know 🙂

    Thread Starter Marlimant


    Thank you. I complemented ACF with Post Status Notifier plugin and both works like a charm.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Field in a email message body’ is closed to new replies.