I have a question about php mail() function.
This function allows multiple recipients that separated by comma, for example:
$mailto="a@test.com,b@test.com,c@test.com";
mail($mailto,$subject,$message,$headers);

If all recipients address are correct, no problem, mail can be sent properly.
However if one address is no longer valid (for instance he leave company), this mail function then failed, those who have valid email address cannot receive email.

Is there a way to skip invalid address and let valid ones still receive email?

Any advice?

Recommended Answers

All 2 Replies

am sorry michael123 but i doubt you can skip such validation as we cannot connect to the D.B of the email service providers and because of that we cannot know who is and who isn't registered hope this helps

Are you sure that mail() doesn't send anything at all if one recipient's email is invalid?

If so, you could maybe use a loop to send separate mails to every email address in an array? E.g.:

$email_addresses = array(
    'email1@email.com',
    'email2@email.com',
    // etc.
);

// Fill these in with whatever you want.
$subject = '';
$message = '';
$headers = '';

// Send the emails.
foreach($email_addresses as $email)
{
    mail($email, $subject, $message, $headers);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.