Support » Plugins » Hacks » Sending email on post publish

  • 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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p


    check subscribe2 plugin

    Try this,
    put in themes functions.php file

    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 );

    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.

    Moderator t-p


    @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. 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sending email on post publish’ is closed to new replies.