2011-03-25 138 views
0

我有一個前端發帖表單,註冊用戶可以在其中起草帖子。我有一個元字段,其中包含起草內容的用戶的電子郵件。現在,當我從後端發佈內容時,我想發送一封電子郵件給用戶,通知該帖子已發佈。在wordpress發佈帖子時向用戶發送電子郵件

任何方向的研究將有所幫助。

謝謝!

回答

0

PHP's mail function應該是一個很好的起點。請記住確保您的php.ini設置正確以發送郵件。

+0

TNX!另外我需要知道如何添加功能,當我點擊wordpress儀表板中的發佈帖子按鈕。 – Sisir 2011-03-25 15:30:03

2
add_action('publish_post', 'send_email'); 
function send_notification($post_id) {  
     $post  = get_post($post_id); 
     $post_url = get_permalink($post_id); 
     $post_title = get_the_title($post_id); 
     $author = get_userdata($post->post_author); 
     $subject = 'Post publish notification'; 
     $message = "Hello,"; 
     $message .= "<a href='". $post_url. "'>'".$post_title."'</a>\n\n"; 
     wp_mail($author->user_email, $subject, $message); 
}