ttmt
ttmt

Reputation: 4984

Wordpress email post content

I have this function in functions.php to send an email when a new post is published.

How can I add the content of the post as the message in the email.

function authorNotification($post_id) {

   $to = '[email protected]';

   $subject = 'New Post';

   $message = $post_id->post_content;

   $headers = 'Content-type: text/html';

   wp_mail($to, $subject, $message, $headers);
}
add_action('publish_post', 'authorNotification');

Upvotes: 0

Views: 338

Answers (1)

Khushboo
Khushboo

Reputation: 1817

Try this :-

function authorNotification($post_id) {

   $to = '[email protected]';

   $subject = 'New Post';

   $post_obj = get_post($post_id); 
   $postcontent = $post_obj->post_content;

   $message = $postcontent;

   $headers = 'Content-type: text/html';

   wp_mail($to, $subject, $message, $headers);
}
add_action('publish_post', 'authorNotification');

Upvotes: 1

Related Questions