2015-10-20 75 views
0

我想發送郵件給用戶,邀請他們看到密碼保護的頁面。我的代碼是:wp_mail - wordpress不發送郵件

function my_project_updated_send_email($post_id) { 

    // If this is just a revision, don't send the email. 
    if (wp_is_post_revision($post_id)) 
     return; 


    if (post_password_required($post_id)) { 

     $post_title = get_the_title($post_id); 
     $post_url = get_permalink($post_id); 
     $subject = 'New Report Published by MySelf'; 

     $email_to=$_POST["email_to"]; 
     $email_to = preg_replace('/\s+/', '', $email_to); 

     $password = $_POST["post_password"]; 
     $password = preg_replace('/\s+/', '', $password); 

     $message = "Here is the link for you on our website:\n\n"; 
     $message .= $post_title . ": " . $post_url . "\n\n"; 
     $message .= "Your Password is :" .$password; 
     $headers = "From: [email protected]"; 

     // Send email to admin. 
     if(($password!=="") || ($email_to!=="")){ 
      wp_mail($email_to, $subject, $message, $headers); 
     } 

    } 

} 

add_action('save_post', 'my_project_updated_send_email'); 

它不發送郵件。請指教。

感謝, 維克拉姆

+0

你在哪裏主辦你的項目?你在本地機器上運行它嗎? – xphan

+0

它在HostGator上。 – Vikram

+0

我認爲這個錯誤在這裏: 'if(($ password!==「」)||($ email_to!==「」)){' '''用'&&替換因爲你想確保兩者都設置好。 – xphan

回答

0

至於你提到在你的代碼,你想發送電子郵件給管理員,代表$ _ POST評論[「EMAIL_TO」]請使用get_option(「ADMIN_EMAIL」)。

例如。 $ email_to = get_option('admin_email');

+0

Nah - 它只會發送給特定用戶。 email_to字段被添加到密碼保護選項。 – Vikram

+0

來自插件** WP-Mail-SMTP **的測試郵件效果很好。那麼問題是什麼? – Vikram

相關問題