What is the potential issue with displaying all email addresses in the recipient field when using PHPMailer?
Displaying all email addresses in the recipient field when using PHPMailer can lead to a privacy concern as it exposes the email addresses of all recipients to each other. To solve this issue, you should use the `addAddress` method to add each recipient individually, ensuring that their email addresses are not visible to others.
// Initialize PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer();
// Add recipients individually
$mail->addAddress('recipient1@example.com', 'Recipient 1');
$mail->addAddress('recipient2@example.com', 'Recipient 2');
$mail->addAddress('recipient3@example.com', 'Recipient 3');
// Set other email parameters
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->Subject = 'Subject of the email';
$mail->Body = 'Body of the email';
// Send the email
if ($mail->send()) {
echo 'Email sent successfully';
} else {
echo 'Email could not be sent';
}