How can PHP be used to distribute emails to different recipients based on their names or other criteria?
To distribute emails to different recipients based on their names or other criteria using PHP, you can create an array mapping recipients to their respective criteria and loop through it to send emails accordingly. You can use conditional statements to check the criteria and send emails to the appropriate recipients.
$recipients = array(
'John' => 'criteria1',
'Jane' => 'criteria2',
'Alice' => 'criteria1',
'Bob' => 'criteria2'
);
foreach ($recipients as $name => $criteria) {
if ($criteria == 'criteria1') {
// Send email to recipients matching criteria1
mail('recipient1@example.com', 'Subject', 'Message');
} elseif ($criteria == 'criteria2') {
// Send email to recipients matching criteria2
mail('recipient2@example.com', 'Subject', 'Message');
}
}