Skip to:
Content
Pages
Categories
Search
Top
Bottom

Sendgrid and buddypress emails


  • dvpl
    Participant

    @dvpl

    I am using sendgrid plugin to send emails, buddypress sending the plain text html. I need HTML email. I also tried to add the following code in function.php but BP_Email showing me null value.

    add_filter( 'bp_email_use_wp_mail', '__return_false' );
    add_filter( 'bp_send_email_delivery_class', function( $delivery_class ) { 
        return 'Implementwpemailbp'; 
    } );
    class Implementwpemailbp implements BP_Email_Delivery
    {
    public function bp_email(BP_Email $email){
    //add_filter('wp_mail_content_type', 'set_html_content_type');
    
    //wp_mail($to, $subject, $message, $headers = '', $attachments = array())
    
    //remove_filter('wp_mail_content_type', 'set_html_content_type');
    var_dump(get_object_vars(BP_Email));
    }
    }

    Please help what I need to update in above code.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You have a typo: var_dump(get_object_vars(BP_Email)). Looking at your function, that’s meant to be var_dump(get_object_vars($email)).


    dvpl
    Participant

    @dvpl

    Thanks,

    I have made the change now it displayed an empty array.

    You could have figured that out with a bit more time spent debugging. Remove your get_object_vars call, it messes things up.


    vinzen
    Participant

    @vinzen

    Hi @dvpl and @djpaul, is this solution working successfully with the mentioned corrections?

    The above is not a complete solution for Sendgrid, no.


    whoweez
    Participant

    @whoweez

    Hi @djpaul,

    I’m playing around with the above code, but adding it to the functions.php file does not prohibit the buddypress email from sending!?

    Furthermore, using sendgrid’s plugin and provided transactional template ID field does not solve anything as only the template without any buddypress/or wordpress related email content is sent – due to no relational placeholders set.

    My aim is to use a custom transactional template at sendgrid for all wordpress and buddypress related content, but from some of your conversations on this I thought “__return_false” on “bp_email_use_wp_mail” should prohibit any BP emails from being sent in the first place as the new class should handle the email sending process…?

    Could you perhaps give more guidelines as to why buddypress emails are still sending with this implemented:

    add_filter( 'bp_email_use_wp_mail', '__return_false' );
    add_filter( 'bp_send_email_delivery_class', function( $delivery_class ) { 
        return 'Implementwpemailbp'; 
    } );
    class Implementwpemailbp implements BP_Email_Delivery{
      public function bp_email(BP_Email $email){
      //add_filter('wp_mail_content_type', 'set_html_content_type');
    
      //wp_mail($to, $subject, $message, $headers = '', $attachments = array())
    
      //remove_filter('wp_mail_content_type', 'set_html_content_type');
      var_dump($email);
      }
    }

    Really appreciate your help 🙂

    Kind Regards,
    Wzz

    @whoweez This old code sample does nothing much at all. I’m not sure what the intent was, this is basically debugging. To answer your specific question:

    I thought “__return_false” on “bp_email_use_wp_mail” should prohibit any BP emails from being sent in the first place as the new class should handle the email sending process…?

    If that filter returns true, then BuddyPress generates a plain text version of the email, and calls WordPress’ wp_mail() function. By default, this is false, but it returns true if wp_mail_content_type() has been configured for HTML, or if wp_mail() has been redeclared (it’s a pluggable function).

    That last bit is key. A lot of email plugins for WordPress re-declare wp_mail(), so for BuddyPress to use those plugins, the default behaviour is to send that plain text version of that email.

    If bp_email_use_wp_mail return false, then it creates a BP_Email_Delivery object, which is what that second filter is changing, which delivery class BuddyPress uses. Inside that class’ bp_email() method is where you would create a custom integration with your Sendmail plugin (or however you approach that integration).

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