How can PHP be used to send emails to multiple addresses simultaneously, such as for a newsletter?
To send emails to multiple addresses simultaneously using PHP for a newsletter, you can utilize the `mail()` function in a loop to send individual emails to each recipient. Make sure to separate the email addresses with commas in the `to` field of the email headers. Additionally, you can use a mailing list or database to store and retrieve the email addresses.
$recipients = array('email1@example.com', 'email2@example.com', 'email3@example.com');
$subject = 'Newsletter Subscription';
$message = 'Thank you for subscribing to our newsletter!';
foreach ($recipients as $recipient) {
$headers = 'From: yourname@example.com' . "\r\n" .
'Reply-To: yourname@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($recipient, $subject, $message, $headers);
}
Keywords
Related Questions
- Are there any specific PHP functions or scripts that can be utilized to automatically remove unnecessary blank lines in a crontab file?
- How can PHP code be optimized to avoid displaying the login form after the user has logged in without refreshing the page?
- What are the limitations of PHP in terms of visual representation, and how can they be overcome?