PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Notify visitor that their post was published

  1. nicole
    Member

    I found this code on this forum in order to notify readers that their submission has been published:

    function email_members($post_ID)  {
    	global $post;
    	$email_to = get_post_meta($post->ID, 'YOUR_CUSTOMFIELD_KEY', true);
    	$headers = 'From: Name <name@name.com>' . \\"\r\n\\";
            $subject = "Your subject here";
    	$message = "Your message here";
        wp_mail($email_to, $subject, $message, $headers);
        return $post_ID;
    }
    
    add_action('publish_post', 'email_members');

    The problem is I am not sure how to use it. This is what I did:
    1) I put "YOUR_CUSTOMFIELD_KEY" in the admin label of the email field.
    2) I replaced Your subject here - with my subject and Your message here with my message.

    It still doesn't work. Should I put the post ID somewhere? If so, where? Anything else that I should do to get it to work?

    Posted 13 years ago on Wednesday August 17, 2011 | Permalink
  2. Did you use YOUR_CUSTOMFIELD_KEY literally, or change it to the name of the custom field, something like "visitor_email"? You should change this YOUR_CUSTOMFIELD_KEY to whatever custom field name you're using to store the visitor email.

    You need to change the name and email too.

    Also, did you add this code the your theme's functions.php?

    There is no need to send the post ID. It is passed automatically when the post is published.

    Posted 13 years ago on Wednesday August 17, 2011 | Permalink