Can this work? I want to send a email when a post is published to the recipient, that is called in custom field.
EDIT I changed the code to another example I found.
function wpr_Notification($post_id) {
$post = get_post($post_id);
$to = get_post_meta($post_id, 'recipient', true);
$headers = 'From: Disctopia Metal Webzine <admin@disctopia.de>';
$title = $post->post_title." has been published";
$message = " Hello ... and so on.... ";
wp_mail($to, $title, $message, $headers);
}
add_action('publish_post', 'wpr_Notification');
Everything works smooth except for the recipient. If I put an static email adress into this field instead of $to, it works. But if I try to get the value of the custom field, it fails.
I tried to see whats the value of $to by putting it into the $message and changing the $to to my own email adress. Well, there was no value at all for the $to.
What is wrong with this variable? The custom field definitely is called "recipient" and is just a text-string.
:(