Multiple admin email addresses
-
Hi there,
I’ve setup a WordPress blog recently and its working fine. I have set two people as administrators of the blog but they are not receiving emails, e.g. new user registration.
I have changed the email address in “Options” but is there a way I can specify two? If not, which file to I have to mod to get this to work? I can’t find it!
Thanks,
Chris
-
seperate the addresses with a semi-colon. I haven’t tested this method yet but should work (assume – makes an ass out of u and me – ass|u|me ?? ).
scrub that last one. It didn’t work. Sorry.
Anyone have any ideas on this? I’m interested in admin email going to two addresses.
Separate them with a comma and a space.
I’m trying to do this as well. Separating them with a comma and a space does not work. Any other ideas?
What I’ve done in the past is to set up a gmail account for the admin account. Have the gmail address forward the email to all the addresses you want.
Obviously you could do this with other email services than gmail, and even your regular domain email server if it allows forwarding.
Also, I use Dagon Design’s Form Mailer, one of my favorite plugins, and well-supported and documented. This plugin allows multiple email addresses as recipients of contact forms, etc., so at least for those purposes it makes it easy to have multiple recipients.
in wp-includes/formatting.php, function sanitize_option(), case ‘admin_email’, I made the following change:
case 'admin_email': $values = explode(",", $value); foreach($values as $k=>$v) $values[$k] = sanitize_email($v); $value = implode(",", $values); break;
then, in wp-includes/pluggable.php, function wp_mail, I made the following change:
function wp_mail( $targets, $subject, $message, $headers = '' ) { $tars = explode(",", $targets); foreach($tars as $to) { // original function code here except for last return line } return $result }
This allows commas between emails in the admin email setting, and ONLY the admin email setting, and the wp_mail function will mail whatever to every email separated by a comma. But, since as stated the admin_email is the only one we allow commas for, this is the only one that can receive this multiple-email functionality. We only return the $result of the attempt to send the last email. I don’t think that will cause any problems though.
This particular method requires a comma, and a comma only, between the email addresses. However, you could change the explode/implode functions to allow whatever delimiter you desire, just make sure to make it something that isn’t valid in email addresses anyway, so you don’t split up someone’s valid email address.
I am having trouble with the second part of the above code. I don’t fully understand this last part in the pluggable.php file. Is someone able to tell me exactly what to do to follow this instruction? Thanks.
// original function code here except for last return line
}
return $resultWell, I give up. I can’t make this work and I am sure I am just not following something in the directions correctly. If anyone is using this fix to have multiple admin email addresses, maybe you can post the actual code in the pastebin or something for me to grab? Thanks!
I mentioned that I was trying to do this to a few people and they all thought it would be a good option to have in the default installation of WordPress.
WT,
I got the code above by stonicus to work, basically you are only editing the top part of a long section of code, the wp_mail function. The last return line is a ways down and so you are pasting the original code into the modified code that stonicus provided EXCEPT that last return $result line. You need to add a } and then add return $result on the next line.
The wp_mail function of the pluggaple.php code should look like this:
function wp_mail( $targets, $subject, $message, $headers = '' ) { $tars = explode(",", $targets); foreach($tars as $to) { // Compact the input, apply the filters, and extract them back out extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) ); global $phpmailer; // (Re)create it, if it's gone missing if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer(); } // Headers if ( empty( $headers ) ) { $headers = array(); } elseif ( !is_array( $headers ) ) { // Explode the headers out, so this function can take both // string headers and an array of headers. $tempheaders = (array) explode( "\n", $headers ); $headers = array(); // If it's actually got contents if ( !empty( $tempheaders ) ) { // Iterate through the raw headers foreach ( $tempheaders as $header ) { if ( strpos($header, ':') === false ) continue; // Explode them out list( $name, $content ) = explode( ':', trim( $header ), 2 ); // Cleanup crew $name = trim( $name ); $content = trim( $content ); // Mainly for legacy -- process a From: header if it's there if ( 'from' == strtolower($name) ) { if ( strpos($content, '<' ) !== false ) { // So... making my life hard again? $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); $from_name = str_replace( '"', '', $from_name ); $from_name = trim( $from_name ); $from_email = substr( $content, strpos( $content, '<' ) + 1 ); $from_email = str_replace( '>', '', $from_email ); $from_email = trim( $from_email ); } else { $from_name = trim( $content ); } } elseif ( 'content-type' == strtolower($name) ) { if ( strpos( $content,';' ) !== false ) { list( $type, $charset ) = explode( ';', $content ); $content_type = trim( $type ); $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) ); } else { $content_type = trim( $content ); } } elseif ( 'cc' == strtolower($name) ) { $cc = explode(",", $content); } elseif ( 'bcc' == strtolower($name) ) { $bcc = explode(",", $content); } else { // Add it to our grand headers array $headers[trim( $name )] = trim( $content ); } } } } // Empty out the values that may be set $phpmailer->ClearAddresses(); $phpmailer->ClearAllRecipients(); $phpmailer->ClearAttachments(); $phpmailer->ClearBCCs(); $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); // From email and name // If we don't have a name from the input headers if ( !isset( $from_name ) ) { $from_name = 'WordPress'; } // If we don't have an email from the input headers if ( !isset( $from_email ) ) { // Get the site domain and get rid of www. $sitename = strtolower( $_SERVER['SERVER_NAME'] ); if ( substr( $sitename, 0, 4 ) == 'www.' ) { $sitename = substr( $sitename, 4 ); } $from_email = 'wordpress@' . $sitename; } // Set the from name and email $phpmailer->From = apply_filters( 'wp_mail_from', $from_email ); $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); // Set destination address $phpmailer->AddAddress( $to ); // Set mail's subject and body $phpmailer->Subject = $subject; $phpmailer->Body = $message; // Add any CC and BCC recipients if ( !empty($cc) ) { foreach ($cc as $recipient) { $phpmailer->AddCc( trim($recipient) ); } } if ( !empty($bcc) ) { foreach ($bcc as $recipient) { $phpmailer->AddBcc( trim($recipient) ); } } // Set to use PHP's mail() $phpmailer->IsMail(); // Set Content-Type and charset // If we don't have a content-type from the input headers if ( !isset( $content_type ) ) { $content_type = 'text/plain'; } $content_type = apply_filters( 'wp_mail_content_type', $content_type ); // Set whether it's plaintext or not, depending on $content_type if ( $content_type == 'text/html' ) { $phpmailer->IsHTML( true ); } else { $phpmailer->IsHTML( false ); } // If we don't have a charset from the input headers if ( !isset( $charset ) ) { $charset = get_bloginfo( 'charset' ); } // Set the content-type and charset $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); // Set custom headers if ( !empty( $headers ) ) { foreach ( $headers as $name => $content ) { $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); } } do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); // Send! $result = @$phpmailer->Send(); } return $result; } endif;
- The topic ‘Multiple admin email addresses’ is closed to new replies.