#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: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (15)
#3
@
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
@
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' );
#6
@
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
@
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
@
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.
#9
@
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:
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
@
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, '' );
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).