How can the PEAR Mail Package be effectively used to send emails with multiple recipient addresses in PHP?
To send emails with multiple recipient addresses using the PEAR Mail Package in PHP, you can simply pass an array of email addresses to the 'send' method of the Mail object. This allows you to send the same email to multiple recipients at once.
<?php
require_once "Mail.php";
$recipients = array("recipient1@example.com", "recipient2@example.com", "recipient3@example.com");
$from = "sender@example.com";
$subject = "Test Email";
$body = "This is a test email sent to multiple recipients.";
$headers = array(
'From' => $from,
'To' => implode(',', $recipients),
'Subject' => $subject
);
$mail = Mail::factory('smtp', array(
'host' => 'smtp.example.com',
'port' => 25,
'auth' => true,
'username' => 'username',
'password' => 'password'
));
$mail->send($recipients, $headers, $body);
?>
Related Questions
- When dealing with extracting text between double quotes in PHP, how can the presence of escape sequences be handled effectively?
- How can I determine the location of uploaded files on the web space when using PHP?
- What are some common pitfalls when trying to locate specific PHP documents using Firebug?