What is the correct syntax for sending an email to multiple recipients in PHP?
When sending an email to multiple recipients in PHP, you can use the `mail()` function along with the `implode()` function to concatenate multiple email addresses separated by a comma. This allows you to send the same email to multiple recipients without having to send individual emails for each recipient.
$to = 'recipient1@example.com, recipient2@example.com, recipient3@example.com';
$subject = 'Multiple Recipients Test';
$message = 'This is a test email sent to multiple recipients.';
$headers = 'From: sender@example.com' . "\r\n" .
'Reply-To: sender@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Keywords
Related Questions
- What potential pitfalls should be considered when processing the $_POST array in PHP?
- How can developers ensure that their code is compatible with PHP 5 before making the switch?
- What are the recommended steps to ensure proper character encoding for PHP files, especially when using Ajax to load content on a webpage?