我想發送郵件給用戶,邀請他們看到密碼保護的頁面。我的代碼是: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');
它不發送郵件。請指教。
感謝, 維克拉姆
你在哪裏主辦你的項目?你在本地機器上運行它嗎? – xphan
它在HostGator上。 – Vikram
我認爲這個錯誤在這裏: 'if(($ password!==「」)||($ email_to!==「」)){' '''用'&&替換因爲你想確保兩者都設置好。 – xphan