BuddyPress Email Notification Ignoring SMTP Server Settings?
-
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?
-
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.
@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?
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.
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' ) ); }
@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' ) ); }
Does this fix still work for you? My buddypress registration emails still don’t go out but the Post SMTP test emails do.
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
@loveplove can you share your wp_mail conditions for WP Mail SMTP?
Can’t seem to make those changes go through.
Thank you.Hi everyone,
Thanks for this feed providing a working solution to an issue apparently shared by many.
@BuddyPress-team, do you guys think it would be possible to implement a solution in bp-core similar to what @uscore713 suggested?
I am not yet familiar enough to comprehend the need to work with plain-text emails when a custom smtp provider is defined…
Many thanks,
Phil
I agree that it is an ongoing issue.
Please open a ticket here.Thanks @shanebp, I have done that 😉 !
Hi @philippebrousse and @shanebp
I’ve seen the ticket(s) (I think #8104 & #8108 are duplicates) about this need.
In the meantime, you can still send BP Emails in
text/html
usingwp_mail
using these filters:
https://gist.github.com/imath/4faef242ae104c65ddb9ec711ea37189Hello, anyone can explain to me more about that, I’m trying to this but HTML email format not working. it’s mean email > customize page showing HTML email format not send to email.
Hello, anyone can explain to me more about that discussion, I’m also trying to this but HTML email format not working. it’s mean email > customize page showing HTML email format not send to email.
I’m using this php file (https://gist.github.com/imath/4faef242ae104c65ddb9ec711ea37189) and it host on my wp-content > Plugins folder.
I found a way to resolve this problem using a mixture of ideas others have shared (including @6logics and @loveplove). I’ve put the details in a blog post here. In summary, what worked for me was the following in the bp-custom.php file:
// Set BP to use wp_mail add_filter( 'bp_email_use_wp_mail', '__return_true' ); // Set messages to HTML remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); add_filter( 'wp_mail_content_type', 'set_html_content_type' ); function set_html_content_type() { return 'text/html'; } // Use HTML template add_filter( 'bp_email_get_content_plaintext', 'get_bp_email_content_plaintext', 10, 4 ); function get_bp_email_content_plaintext( $content = '', $property = 'content_plaintext', $transform = 'replace-tokens', $bp_email ) { if ( ! did_action( 'bp_send_email' ) ) { return $content; } return $bp_email->get_template( 'add-content' ); } //Optionally remove the filter above after it's run remove_filter('wp_mail','redirect_mails',20); // Optionally change your email address add_filter('wp_mail_from','noreply_from'); function noreply_from($from) { return 'noreply@YOUR_DOMAIN.org'; //Replace 'YOUR_DOMAIN.org' with email address } // Optionally change your from name add_filter('wp_mail_from_name','noreply_from_name'); function noreply_from_name($name) { return 'YOUR_DOMAIN No-Reply'; //Replace 'YOUR_DOMAIN No-Reply' with the from name }
- You must be logged in to reply to this topic.