WP_Mail
WP_Mail copied to clipboard
Send multiple email
$email = WP_Mail::init()
->to([
'[email protected]'
'[email protected]'
])
->cc('[email protected]')
When use like this, all receviers can view all emails in to
section. Is anyway to show only recever mail?
@bilalmalkoc having the same issue, did you manage to figure out a solution to this?
@zkingdesign no i can't
@bilalmalkoc , what I did is that I've put the code into a foreach, and looped through it.
foreach ($emails as $email) {
$item = WP_Mail::init()
->headers("<". get_option('admin_email') .">")
->to($email)
->subject('Update')
->send();
}
@zkingdesign it can gives timeout error when you try for 1000+ emails.
@bilalmalkoc from what you have described there is no actual issue with the code. In fact it's working just how it should. If you want to send the same email to multiple people, but hide who you sent that to, you have to use BCC (Blind Carbon Copy) not To or CC (Carbon Copy). That way each recipient get their own copy of the email. Also if you are trying to send to 1000+ people at once you should probably be doing that in a cron or queued job outside of WP. That way you avoid your web server (Apache/Nginx etc) Timing out the request. @anthonybudd This is not a bug and should be closed.
Hello, Trying to pass an Array to the TO field, I'm getting two PHP warnings: PHP Warning: preg_match() expects parameter 2 to be string, array given in /wp-includes/pluggable.php on line 385 [20-Mar-2020 21:55:51 UTC] PHP Warning: trim() expects parameter 1 to be string, array given in /wp-includes/class-phpmailer.php on line 873
Is anyone else getting this issue?
Hey folks, found the issue.... here: return wp_mail($this->to, $this->buildSubject(), $this->render(), $this->buildHeaders(), $this->attachments);
this should be: return wp_mail($this->to[0], $this->buildSubject(), $this->render(), $this->buildHeaders(), $this->attachments);
Seems like some code is creating a multi-dimensional array... I guess?