1

I am trying this on wordpress, trying to email multiple email address. I have 2 email addresses in the database.

Here is the code:

$r = $wpdb->get_results($wpdb->prepare( "SELECT * FROM wp_users", $ID, $user_email ));

foreach ($r as $row) {

$to       = '[email protected]';
$bcc = $row->user_email;
$subject  =  $_POST["subject"];
$message  =  $_POST["message"];
$headers  = 'From: [email protected]' . "\r\n" .
            'Reply-To: [email protected]' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
    echo "Email sent";
}    
else {
    echo "Email sending failed";
}

It's sending emails BUT what's happening is that the TO ([email protected]) is getting 2 emails and the $bcc is getting none.

What am I doing wrong here?

1 Answer 1

3

Yep, this behavior it is pretty normal, you forgot to put in $headers the Bcc: part, it should be like:

$headers  = 'From: [email protected]' . "\r\n" .
            'Reply-To: [email protected]' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Bcc: '.$bcc. "\r\n".
            'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.