Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress Email Notification Ignoring SMTP Server Settings?


  • kmligue
    Participant

    @kmligue

    I installed https://wordpress.org/plugins/postman-smtp/ on my WP (v 4.6) + BuddyPress (v 2.6.2) site, then configured it to use my Gmail account’s SMTP server settings.

    The emails sent by the site uses the SMTP settings when:

    – A member registers and PMPRo (https://tl.wordpress.org/plugins/paid-memberships-pro/) sends out an email confirmation
    – Emails sent using the plugin (https://wordpress.org/plugins/email-users/)

    (I can see these sent emails in the “Sent” folder of my Gmail account.)

    However, when BuddyPress sends out an email (e.g. email notification for friend request, etc.), it seems to ignore the SMTP server settings I have configured. Instead, it uses the server’s default.

    How do I make BuddyPress email notifications send using my Gmail SMTP server settings?

Viewing 7 replies - 1 through 7 (of 7 total)

  • Brajesh Singh
    Participant

    @sbrajesh

    The problem is BuddyPress does not uses wp_mail.

    The plugin postman-smtp overrides the wp_mail function to send emails, so any emails sent via wp_mail is sent through the smtp settings provided.

    BuddyPress uses custom instance of PHP Mailer to send emails and that’s why these settings are not effective. You can force BuddyPress to use wp_mail by putting the following code in your bp-custom.php

    
    add_filter('bp_email_use_wp_mail', '__return_true');
    

    But in that case BuddyPress will only send text emails (Not the rich html emails you might have seen earlier).

    Hope that helps.


    kmligue
    Participant

    @kmligue

    @sbrajesh, thank you for your suggestion. It works. However, we do need to send rich HTML emails. Is there a way we can configure BuddyPress’ custom instance of PHP Mailer to use our SMTP server?


    6logics
    Participant

    @6logics

    we do need to send rich HTML emails. Is there a way we can configure BuddyPress’ custom instance of PHP Mailer to use our SMTP server?

    I am also looking forward to this option. I am using Gmail SMTP plugin to send email and it is causing to send plain text.


    6logics
    Participant

    @6logics

    I fixed it by changing the code in function bp_send_email in file /buddypress/bp-core/bp-core-functions.php.

    Before:

    $must_use_wpmail = apply_filters( 'bp_email_use_wp_mail', $wp_html_emails || ! $is_default_wpmail );
    
    	if ( $must_use_wpmail ) {
    		$to = $email->get( 'to' );
    
    		return wp_mail(
    			array_shift( $to )->get_address(),
    			$email->get( 'subject', 'replace-tokens' ),
    			$email->get( 'content_plaintext', 'replace-tokens' )
    		);
    	}

    After:

    $must_use_wpmail = apply_filters( 'bp_email_use_wp_mail', $wp_html_emails || ! $is_default_wpmail );
    
    	if ( $must_use_wpmail ) {
    		$to = $email->get( 'to' );
    
    		return wp_mail(
    			array_shift( $to )->get_address(),
    			$email->get( 'subject', 'replace-tokens' ),
    			$email->get_template( 'add-content' )
    		);
    	}

    Jay
    Participant

    @uscore713

    @6logics – Thanks! This is exactly what I needed to effect the use of BuddyPress email templates with Postman SMTP.

    It’s a shame the core code has to be modified, but until some sort of filter can be provided (eg, “bp_email_force_use_of_templates”), this seems to be our only recourse. Perhaps something along the lines of:

    $must_use_wpmail = apply_filters( 'bp_email_use_wp_mail', $wp_html_emails || ! $is_default_wpmail );
    
    	if ( $must_use_wpmail ) {
    		$to = $email->get( 'to' );
    
    		$use_template = $wp_html_emails && 
    		return wp_mail(
    			array_shift( $to )->get_address(),
    			$email->get( 'subject', 'replace-tokens' ),
    			apply_filters( 'bp_email_force_use_of_templates', false ) ?
    				$email->get_template( 'add-content' ) :
    				$email->get( 'content_plaintext', 'replace-tokens' )
    		);
    	}
    

    balebond
    Participant

    @balebond

    Does this fix still work for you? My buddypress registration emails still don’t go out but the Post SMTP test emails do.


    Khurshid Faizullaev
    Participant

    @loveplove

    Hi everyone. I am doing a site called https://loveplove.com

    After having read all forums, what worked for me was using WP Mail SMTP plugin was putting the following code. Please note I am just putting together various codes together from authors in those forums so you find it easily. In your bp-core-functions php file add the following:

    add_filter(‘bp_email_use_wp_mail’, ‘__return_true’);

    add_filter( ‘wp_mail_content_type’, function( $content_type ) {
    $content_type = ‘text/html’;
    return $content_type;
    } );

    $must_use_wpmail = apply_filters( ‘bp_email_use_wp_mail’, $wp_html_emails || ! $is_default_wpmail );

    if ( $must_use_wpmail ) {
    $to = $email->get( ‘to’ );

    return wp_mail(
    array_shift( $to )->get_address(),
    $email->get( ‘subject’, ‘replace-tokens’ ),
    $email->get_template( ‘add-content’ )
    );
    }

    add_filter( ‘wp_mail’, function( $array ) {
    // Set conditions here.

    $array[‘message’] = ‘Change this’;
    return $array;
    } );

    DELETE THE FOLLOWING:

    $must_use_wpmail = apply_filters( ‘bp_email_use_wp_mail’, $wp_html_emails || ! $is_default_wpmail );

    if ( $must_use_wpmail ) {
    $to = $email->get( ‘to’ );

    return wp_mail(
    array_shift( $to )->get_address(),
    $email->get( ‘subject’, ‘replace-tokens’ ),
    $email->get( ‘content_plaintext’, ‘replace-tokens’ )
    );
    }

    LovePlove

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