Track from which subdomain emails are being sent by email headers.

I've started receiving a lot of identical emails from one of my Multisite installations. The emails I receive are all identical, although, one is sent to me at and the other to (I get them two at a time. How do i track down which sub-domain they're coming from?

  • Panos

    Hi Steve!

    From headers only I can't think of any way to see from which blog of your multisite has been sent. BTW here is an article I find informative regarding email headers:

    Only way I can think of is to include the blog id or/and blog name in the content of the email sent. Here is a simple snippet that you can insert in a mu-plugin:

    add_filter( 'wp_mail', function( $atts ){
    	$emails = array( '', '' );
    	if( is_multisite() && in_array( $atts[ 'to' ], $emails ) ){
    		$sent_by = '<p>Sent by: <br />';
    		$sent_by .= 'Blog id: #' . get_current_blog_id() . '<br />';
    		$sent_by .= 'Blog name: ' . '<a href="' . get_bloginfo('url') . '" >' . get_bloginfo('name'). '</a>';
    		$sent_by .= '</p>';
    		$atts[ 'message' ] .= $sent_by;
    	return $atts;
    }, 10 );

    This should add blog id and title at the end of the email content only if the receiver is one of your specified emails. You will need to modify line
    $emails = array( '', '' );
    and include the emails you need.

    I suggested using a mu-plugin instead of a theme so that you do not need to paste it in each theme's functions.php as each blog on your multisite may use different themes. If you don't know what is a mu-plugin or how to create on please read through here:

    In short, all you need to do is create a folder named "mu-plugins" in your wp_content folder if it doesn't already exist. Create a new file with the file extension ".php", eg "custom-functions.php". Open file with an editor (eg notepad) and insert in the begging "<?php". Then you can paste the snippet I shared above under that line.

    Hope this helps!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.