Skip to:
Content

BuddyPress.org

Opened 5 years ago

Closed 4 years ago

Last modified 18 months ago

#8159 closed defect (bug) (fixed)

bp_send_email not sending emails to all if passing multiple email ids since 4.0.0 update

Reported by: alexhal's profile alexhal Owned by: djpaul's profile DJPaul
Milestone: Awaiting Review Priority: high
Severity: major Version: 2.5.0
Component: Emails Keywords: reporter-feedback needs-testing
Cc:

Description

Hi we are using bp_send_email to send email to single and multiple users.
We are sending array of email :

`
$emails = [
'abc@…',
'efg@…',
'hij@…'
]
$email_type = 'custom';
$bpargs = array(
'tokens' => array('post.name'=>'customtoken')
);
bp_send_email( $email_type,$emails, $bpargs );`

So after execution it is only sending email to first email in array : abc@…

It use to send email to all emails in that array previously .

however running a loop and sending email to one user at a time is working :

`
$emails = [
'abc@…',
'efg@…',
'hij@…'
]
$email_type = 'custom';
$bpargs = array(
'tokens' => array('post.name'=>'customtoken')
);
foreach($emails as $email){
bp_send_email( $email_type,$email, $bpargs );
}
`

Please tell us what exactly is wrong with this ?
Does bp_send_email function does not supports sending email to multiple email in one go.We really want to avoid the for loop .

Attachments (3)

bp1.png (13.7 KB) - added by bouncingsprout 5 years ago.
WooCommerce email field
bp2.png (15.5 KB) - added by bouncingsprout 5 years ago.
Gravity Email field
bp3.png (26.5 KB) - added by bouncingsprout 5 years ago.
WordFence email field

Download all attachments as: .zip

Change History (15)

#1 @imath
5 years ago

  • Version changed from 5.0.0 to 2.5.0

Hi @alexhal

Thanks for your feedback. I'm going to look at it.

I just wanted to make sure you tested it without any plugins active as after checking our unit tests suite: sending multiple emails at once hasn't failed so far (FYI if there was a problem: it should).

#2 @imath
5 years ago

  • Keywords reporter-feedback added

I've just tested, when I'm using 2 users, the "To" email field is containing the emails of these two users separated with a comma, so I guess they both receive the email. Here's what I get testing with mailhog:

https://cldup.com/N5CZLpkcH9.png

So to me, it's behaving the right way.

#3 @bouncingsprout
5 years ago

I'm having the same issue. I have an input field where users can enter comma-separated email addresses. My plugin successfully removes any spaces, and explodes into an array using the commas. This passes an array of email addresses to bp_send_email just as @alexhal above.

However, bp_send_email only successfully delivers to the first address in the array.

@imath, it looks like you have used a name<address> syntax in your test, which looks like it may have come from an array of user IDs? In that case, I would expect your test to have succeeded as you can pass an array of IDs to the function. Perhaps the ticket title is misleading, as @alexhal isn't passing IDs at all, but an array of email address strings?

#4 @imath
5 years ago

To be sure I understand the issue, what needs to be checked ?

array( 1, 2 ); or array( 'one@mail.mail', two@mail.mail' );

#5 @bouncingsprout
5 years ago

Thanks @imath, it's the second one. An array of email addresses.

#6 @imath
5 years ago

  • Keywords needs-testing added

Hi @bouncingsprout and @alexhal

Reading inline comments + code inside the BP_Email_Recipient class, when you want to send an email to a list of email addresses, you need to use an array keyed by email addresses containing the user name for it to work. For example :

$tos = array(
	'user1@ma.il' => 'User 1',
	'user2@ma.il' => 'User 2',
	'user3@ma.il' => 'User 3',
); 

I haven't tested though, could you test using such an associative array to see if it's fixing your issue ?

#7 @bouncingsprout
5 years ago

Hey @imath,

Thank you for looking at this, but sadly, this won't help. The reason for the array of email addresses rather than array of users is because they may be external to the site, so they won't have usernames.

Thanks again!

#8 @imath
5 years ago

Ok, but the "user name" doesn't need to be the WordPress/BuddyPress user name, it can be first name + last name for example.

@bouncingsprout
5 years ago

WooCommerce email field

@bouncingsprout
5 years ago

Gravity Email field

@bouncingsprout
5 years ago

WordFence email field

#9 @bouncingsprout
5 years ago

Hey @imath - thank you so much for your help so far.

I'm really sorry for the confusion, which I am certain is because I am not explaining the problem well enough.

Let me reframe the issue in another way. I develop BuddyPress plugins and would like to be able to offer an input field, so that multiple email addresses can be entered. This is currently something that the standard wpmail handles well. For reference:

Here it is in WooCommerce:
WooCommerce email field

In Gravity forms:
Gravity Email field

In Wordfence:
WordFence email field

At the moment, I cannot offer this to my users as BuddyPress does not seem able to parse the email addresses, either as a comma separated string, or as (once exploded) an array of addresses.

I hope that explains the situation slightly better, and I apologise again for the confusion.

Ben

#10 @imath
5 years ago

I see, I think you can achieve it doing something like this:

$emails = array( 'user1@ma.il', 'user2@ma.il' );
$to = array_fill_keys( $emails, '' );

#11 @imath
4 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

I'm going to close this ticket, as without any updates I understand the code I shared in my last comment may have fixed the issue. If not, don't hesitate to reopen the ticket.

#12 @alexhal
18 months ago

Hi this is still an issue with multiple email ids when
add_filter( 'bp_email_use_wp_mail', 'return_true' );

filter is used

it uses the wp_mail function which does not understands or send email to multiple ids please fix it soon

Note: See TracTickets for help on using tickets.