WordPress.org

Ready to get started?Download WordPress

Forums

Sending email on post publish (5 posts)

  1. scheda
    Member
    Posted 2 years ago #

    I've got a site using the User Submitted Photos plugin, with some modifications.

    I'm capturing the user's email when they submit a photo to my site, which then gets set as a draft post.

    I mass approve posts a few times a day, and I need a way to send an email to the users when their post is approved.

    So far it looks like I need to use the publish_post hook, but there's no documentation on it so I don't really understand how to use it.

    I've got the email in a meta field, so my only real problem is pulling that when a post gets published.

    Here's how I imagine it working is pseudo code...

    Function sendEmail
        id = Post ID
        email = get_post_meta(id, 'email')
        //code to send email here

    So, is publish_post the right hook to be using here and if so, how do I get the post ID of the post being published?

    Thanks everyone for your help

  2. Tara
    Member
    Posted 2 years ago #

    check subscribe2 plugin

  3. Amit_k
    Member
    Posted 2 years ago #

    Try this,
    put in themes functions.php file

    <?php
    add_action( 'save_post', 'send_email' );
    function send_email( $post_id ) {
    // lets check if post is not revision
    	if ( !wp_is_post_revision( $post_id ) ) {
    		$post_url = get_permalink( $post_id );
    		$subject = 'Image is approved';
    		$message = "Your image is approved:\n\n";
    		$message .= "<a href='". $post_url. "'>Click here to view</a>\n\n";
    		$email = get_post_meta($post_id, 'email')
    		//sends email
    		wp_mail($email, $subject, $message );
    	}
    }
    ?>
  4. shashikant upadhyay
    Member
    Posted 1 year ago #

    hi
    i am using to wordpress 3.5.1 and newsletter plugin ..but i want to add post publish in my site and send email to my email_id.

  5. Tara
    Member
    Posted 1 year ago #

    @shashikant: It's easier for volunteers to help you if you have your own topic. Therefore, as per the Forum Welcome, please post your own topic. Posting in an existing topic prevents from being able to track issues by topic. :)

Topic Closed

This topic has been closed to new replies.

About this Topic