Add multiple recipients via BCC on wp_mail()

You’d write them the same way you would any other email, the knowledge you need to do this is Email header knowledge, not WP knowledge. Those are raw email headers, and aren’t a special WP format.

Since each item in the array is a line in the header of the email, we need to know how an email client writes out a BCC line.

This article describes all the various headers: https://mailformat.dan.info/headers/from.html

We can also get an example of specifying multiple emails in a header field by looking at the headers in any Email client. For example, here’s a header field for an email I recieved from Github:

Cc: Tom J Nowell <[email protected]>, Author <[email protected]>

I got this in gmail by using the 3 dot dropdown and clicking show original. You won’t see a BCC field this way, but given that multiple emails are always specified the same way, I trust you can make the minor leap and reuse the same format in the BCC field. E.g.

    $headers = [
        'Content-Type: text/html;'
        'charset=UTF-8',
        'Cc: Tom J Nowell <[email protected]>, Author <[email protected]>',
    ];

    wp_mail( $to, $subject, $body, $headers );

I trust you can make the final adjustment yourself, I won’t cover looping over an array of strings and joining them together as that’s basic PHP that I trust you can handle

Leave a Comment