How can multiple email recipients be specified when using the PHP mail function?

To specify multiple email recipients when using the PHP mail function, you can separate the email addresses with commas within the $to parameter. This allows you to send the email to multiple recipients in one go. Simply list all the email addresses you want to send the email to, separated by commas.

$to = 'recipient1@example.com, recipient2@example.com, recipient3@example.com';
$subject = 'Subject of the email';
$message = 'This is the body of the email';
$headers = 'From: sender@example.com' . "\r\n" .
    'Reply-To: sender@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);