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.

The WP systems sends a lot of mails to authors. There also plugins who use email notifications for authors.

But, let say I have a user, who is managed by two persons (because it's a company, an entity that is more then one person) - I want all the emails to be sent also to a second Email address, that I will enter in the profile page of that WP user.

What is the best way to achieve this? I know how to add a field to the profile page, but I don't know how to send every notification that the user gets to the second email address. please help :)

share|improve this question
    
Have you tried using comma separated values for the email? Just a thought... –  m0r7if3r Feb 17 '12 at 13:00
    
tried it, just for the elimination process. it didn't worked. –  Asaf Chertkoff Feb 17 '12 at 14:49
    
What exactly didn't work out? –  kaiser Feb 19 '12 at 14:51
    
@kaiser, try it yourself - it would output an error saying it is not a valid email address. –  Asaf Chertkoff Feb 20 '12 at 16:18
    
Yea, sure - building a setup to test this. Did you actually var_dump the output to make shure you ain't got the comma or white spaces? –  kaiser Feb 20 '12 at 16:31
show 5 more comments

2 Answers

up vote 1 down vote accepted

Not a WP specific solution, but you can usually set-up an alias/forwarder in your email system that sends a copy to both people.

e.g.

timandjoe@domain.com

sales@domain.com

etc.

share|improve this answer
    
yes. but's that isn't always possible. let say, when the host is lousy and won't let me manage my emails properly... –  Asaf Chertkoff Feb 23 '12 at 21:03
1  
If you have a lousy host it's probably time to move hosts, not route around their lousiness ;-). This is certainly easier than a code based solution (for non technical users). –  Refiner Feb 27 '12 at 22:36
    
Yes, I know. but just for the challange. what would you do. in the end i've changed hosting and forward the Email as you suggested, and as I also thought would be the best solution. But what if? –  Asaf Chertkoff Mar 2 '12 at 10:56
add comment

A suggestion, albeit a sorta hack, I'd like to make is to use a mailing list. You can add an infinite number of emails to a mailing list.

An alternative you could do is to use the publish_{$posttype} hook to send email notificiations through wp_mail. The wp_mail function's $to parameter takes either a string or an array so you could pass in multiple email addresses.

EDIT:

function notify_users_of_new_post($post_id) {
    // Get list of subscribers and their secondary email address stored in wp_usermeta
    $user_query = get_users('blog_id=1&orderby=nicename&role=subscriber&fields=all_with_meta');

    $bName = get_bloginfo('name');
    $permalink = get_permalink($post_id);
    foreach($user_query as $user) {
        $email = $user->email;

        if (isset($user->secondary_email) AND !empty($user->secondary_email)) {
            $email = array( $user->email, $user->secondary_email );
        }

        wp_mail($email, sprintf('New Blog Entry on %s', $bName), sprintf('A new entry has been published to %s. View it clicking here: %s', $bName, $permalink));
    }
}
add_action('publish_post', 'notify_users_of_new_post');

I attempted a sample code block (above). A suggestion if you plan on using this on a production site, use a cron job if you have a lot of registered users, otherwise I'm pretty sure this will cause a timeout in PHP.

share|improve this answer
    
+1 Would - as always - be kool to see a code sample –  kaiser Feb 18 '12 at 13:42
    
Attempted a codeblock. Though I'm unfamiliar with these functions get_users (confused by Codex's query $args) and wp_mail by simply not having used it before. –  Zack Feb 18 '12 at 18:39
add comment

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.