How can you dynamically add multiple email recipients in a PHP script based on user input?
When dynamically adding multiple email recipients in a PHP script based on user input, you can use an array to store the email addresses provided by the user. You can then loop through this array and add each email address as a recipient in the email sending function.
<?php
// Get user input for email addresses
$user_input_emails = $_POST['emails'];
// Split the input into an array of email addresses
$emails = explode(',', $user_input_emails);
// Loop through the array and add each email address as a recipient
foreach ($emails as $email) {
$to = trim($email);
$subject = 'Test Email';
$message = 'This is a test email.';
$headers = 'From: your_email@example.com';
// Send the email
mail($to, $subject, $message, $headers);
}
?>
Related Questions
- What are the potential pitfalls of counting open ProFTPD processes using PHP?
- How can PHP be used to extract content from a website, including images and CSS files, without accessing external servers?
- What potential pitfalls should be considered when modifying a third-party PHP script like the oxwall Community Script?