change the email ‘from’ name (BuddyPress email templates)
-
How do you change the email address and name (BuddyPress email templates).
The following works only for WordPress emails such as the email to recover password, but it doesn’t work for any of the BuddyPress emails:
// change email address function change_wp_mail_from( $email ){ return 'support@mysite.com'; } add_filter( 'wp_mail_from', 'change_wp_mail_from' ); // Change email name function change_wp_mail_name( $name ){ return 'My Site'; } add_filter( 'wp_mail_from_name', 'change_wp_mail_name' );
Any help appreciated.
-
Try:
add_action( 'bp_email', function( $email_type, $email_obj ) { $email_obj->set_from( "custom@example.com", "Custom Website Name" ); }, 10, 2 );
https://codex.buddypress.org/emails/#filter-from-address-and-name
i use this plugin for that: https://wordpress.org/plugins/wp-mail-options/
FYI
wp_mail_from_name
andwp_mail_from
support are coming back in BuddyPress 2.5.3. Thanks to everyone’s feedback regarding this.Is this problem causing BP emails to appear as text, for example:
Instead of as a mailto: link:
?
Same thing with BP images, see:
http://thelincolnacademyofillinois.org/members/peter-bensinger/
Sorry, this is how an email address is appearing on a profile page.
<a href="mailto:Peter.bensinger@bensingerdupont.com">Peter.bensinger@bensingerdupont.com</a>
When is BP 2.5.3 coming out?
The problem is the < and > are being escaped, so the image is output as:
<td class="data"><img src="http://thelincolnacademyofillinois.org/wp-content/uploads/profiles/16/peter-bensinger.jpg" alt="" /></td>
instead of
<td class="data"><img src="http://thelincolnacademyofillinois.org/wp-content/uploads/profiles/16/peter-bensinger.jpg" alt="" /></td>
I can’t get the escaped characters to appear in a way that reflects what BuddyPress is outputting to the screen.
Please look at the page:
http://thelincolnacademyofillinois.org/members/peter-bensinger/
You will see what I mean.
add_action( 'bp_email', function( $email_type, &$email_obj ) { $email_obj->set_from( "noreply@mydomain.com", "Blog website" ); }, 10, 2 );
Using this returns 2 warnings for me.
Warning: Parameter 2 to {closure}() expected to be a reference, value given in …/wp-includes/plugin.php on line 525
Warning: Cannot modify header information – headers already sent by (output started at …/wp-includes/plugin.php:525) in …/wp-includes/pluggable.php on line 1171
The mail still gets send but it won’t change the from email. I turned wp_mail on for now as I also don’t know how to change the bp mail, mail_from setting.
add_filter( 'bp_email_use_wp_mail', '__return_true' );
Thanks for the code. It seems to have one problem, but I think I fixed it, it now works for me.
The code you provided:
add_action( 'bp_email', function( $email_type, &$email_obj ) { $email_obj->set_from( "custom@example.com", "Custom Website Name" ); }, 10, 2 );
This brings up this error right after signing up:
Warning: Parameter 2 to {closure}() expected to be a reference, value given in /home/####/public_html/wp-includes/plugin.php on line 525
Changing
&$email_obj
to$email_obj
worked for me. The following code works:add_action( 'bp_email', function( $email_type, $email_obj ) { $email_obj->set_from( "custom@example.com", "Custom Website Name" ); }, 10, 2 );
Thx @sm60. I’ve adjusted my answer and the codex entry.
Thanks for the code snippets.
Question, is there a way to change the reply-to field in sent emails? I’ve tried to add it as extra arguments on the same set_from method, and i have also tried set_reply_to, but neither worked. The sent from works perfectly, but the reply-to keeps showing the wordpress main email.@rodolvertice I found a solution by copying @shanebp’s code and replacing ‘set_from’ with ‘set_reply_to’, as in:
add_action( 'bp_email', function( $email_type, $email_obj ) { $email_obj->set_reply_to( "custom@example.com", "Custom Website Name" ); }, 10, 2 );
- You must be logged in to reply to this topic.