Skip to:

Very strange BP Emails behaviour

  • I’m using Sendgrid plugin to send emails. It replaces the wp_mail() function included with WordPress. Also BuddyPress 2.5.2 and WordPress 4.4.2.

    In the BuddyPress source code I found a filter 'bp_email_use_wp_mail', which skips BP’s email handling and instead sends everything to wp_mail() if wp_mail_content_type() has been configured for HTML, or if wp_mail() has been redeclared. That’s exactly my case (both if‘s).

    So to omit using wp_mail() – which sends data in plain text only – I wrote this:

    function cd_fix_bp_email_for_sendgrid( $status ) {
        return false;
    add_filter( 'bp_email_use_wp_mail', 'cd_fix_bp_email_for_sendgrid' );

    And now I’m using BuddyPress sending functionality. And not receiving emails at all.

    I opened bp_send_email() function and printed debug information right before this line:

    do_action( 'bp_send_email_success', $status, $email );

    I see that $status is true, $email – is not good (content_html == content_plaintext).

    I opened class-bp-phpmailer.php (which actually sends all the data) and printed the $phpmailer object right before return $phpmailer->Send(); call – everything is fine (template populated, content processed properly) – but no email in my inbox.

    So to sum up:

    1. Sendgrid redefines wp_mail(), I filtered this to use bp_email()
    2. $phpmailer has proper content
    3. email is not sent

    Dunno what to do next to start using these cool new BuddyPress Emails 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • I think I know but can you dump the entire email object — in that bp_send_email_success filter — and share it with me? Either on github gist or email me or however.

    I’m going to assume that you haven’t changed post_content to match post_excerpt on purpose 😉

    Here is the BP_Email object:

    And sure, I didn’t modify it. Only that BP Email to WP Email name filter bridge plugin is installed (from those, that are doing anything with BuddyPress emails)

    Filtering this to false is only going to try to send the email via PHPMailer. This doesn’t always work depending on server configuration, which is why SMTP plugins are quite common.

    You need to create your own BP_Email_Delivery class. Someone else is literally asking me this right now so I’ll throw together some example code quickly…

    Discussion with other person ended up with me not writing code. @slaffik I’ll try to get to this in the next day or two, but you need to implement your own BP_Email_Delivery class, like BP_PHPMAiler, and filter bp_send_email_delivery_class, AND set bp_email_use_wp_mail to return false.

    Got it, thanks! Although that’s a bit strange, considering the code I see (existence of BP_PHPMailer).

    Anyway will be waiting for you here (if possible) before implementing a class, to get some direction or anything (and I’m sure there will be something) useful. I’m not (right now) that email or SMTP-savvy developer.


    That’s for Mandrill. It relies on the fact that the wpMandrill plugin replaces wp_mail() so it gets the email data it needs, and just calls wp_mail().

    Maybe you can use it as a base

    Awesome! Thank you, I will investigate and use that.



    Hi, i’m having the same problem, and I wonder if you have found any solution for SendGrid.


Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar