WP_Mail icon indicating copy to clipboard operation
WP_Mail copied to clipboard

Send multiple email

Open bilalmalkoc opened this issue 6 years ago • 7 comments

    $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 avatar Dec 28 '18 09:12 bilalmalkoc

@bilalmalkoc having the same issue, did you manage to figure out a solution to this?

zkingdesign avatar Feb 04 '19 11:02 zkingdesign

@zkingdesign no i can't

bilalmalkoc avatar Feb 04 '19 11:02 bilalmalkoc

@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 avatar Feb 04 '19 11:02 zkingdesign

@zkingdesign it can gives timeout error when you try for 1000+ emails.

bilalmalkoc avatar Feb 04 '19 13:02 bilalmalkoc

@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.

r-nicol avatar Feb 26 '19 13:02 r-nicol

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?

mukeshwani avatar Mar 20 '20 22:03 mukeshwani

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?

mukeshwani avatar Mar 20 '20 22:03 mukeshwani