Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom notification function for our comments editor, who prefers to have all comments from one article threaded together in her email client. To achieve this, I'm creating a custom message-ID for the first comment on an article, then setting that as the In-Reply-To for future comment notifications.

This is working to some extent - I can see the additional headers in the mail client - however, the first message is being created with TWO Message-IDs. In other words, the one I passed into the headers is NOT overriding the one Wordpress is autogenerating. Therefore, the threading doesn't work.

Is this a bug with Wordpress? I don't want to resort to hunting down the actual WP_mail function and editing core code; and I'm not sure that would even work. Is this something more fundamental with PHP Mail function that I can't change perhaps?

$messageIDtoCreate = $post->ID.".".time(); // post ID, and current timestamp
add_post_meta( $post->ID, 'messageID', $messageIDtoCreate);
// add to the email headers
$message_headers .= "Message-ID: <".$messageIDtoCreate."@test.com>\n";

Thanks in advance.

share|improve this question

1 Answer 1

You can filter the $phpmailer object. Something like this should do the trick (not tested):

add_action( 'phpmailer_init', 'wpse_52555_msg_id' );

function wpse_52555_msg_id( &$phpmailer )
{
    $msg_id = get_post_meta( get_the_ID(), 'messageID', TRUE );
    '' !== $msg_id and $phpmailer->MessageID = $msg_id . '@test.com';
}
share|improve this answer
    
Thanks, this looks promising! I tried changed get_the_id() to $post->ID as it wasnt inside of a loop, but thats not working either. I think it doesn't have access to the $post object when called as a filter like this? –  James Bruce May 18 '12 at 15:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.