For each post, I want to send an email once it has been published. The email address is stored in a custom field.
I have added a custom field . I have got your_email
for the 'name'and the value is my email address (as a test).
I have got the following code in functions.php :
function ik_send_email($post_id){
$email_address = get_post_meta($post_id, 'your_email', true);
$subject = "Your Subject Here!";
$body = "Thank you for your submission! Your story has been approved!";
$headers = 'From: From Address <[email protected]>' . "\r\n";
if(wp_mail($email_address, $subject, $body, $headers)){
//mail sent!
} else {
//failure!
}
}
add_action('publish_post','ik_send_email');
So once I click 'published' it should send an email to the address entered in the custom field, but I'm not getting an email? Any tips someone can give please?