phpmailerHow can I use PHPMailer to send emails with a BCC address?
PHPMailer is an open-source library for sending emails with PHP. To use PHPMailer to send emails with a BCC address, you need to include the PHPMailer library in your PHP script and create an instance of the PHPMailer class.
// Include PHPMailer library
require_once 'PHPMailer/PHPMailerAutoload.php';
// Create instance of PHPMailer
$mail = new PHPMailer;
// Set BCC address
$mail->addBCC('[email protected]');
You can then add the other required details such as the sender, recipient, and subject, as well as the message body. Finally, you can send the email using the send()
method.
// Set sender, recipient, subject, and body
$mail->setFrom('[email protected]', 'From Name');
$mail->addAddress('[email protected]', 'To Name');
$mail->Subject = 'PHPMailer BCC Test';
$mail->Body = 'This is a test of PHPMailer BCC';
// Send email
if ($mail->send()) {
echo "Email sent successfully";
}
else {
echo "Error sending email: " . $mail->ErrorInfo;
}
Output example
Email sent successfully
Code explanation
require_once 'PHPMailer/PHPMailerAutoload.php';
: Include PHPMailer library.$mail = new PHPMailer;
: Create instance of PHPMailer class.$mail->addBCC('[email protected]');
: Set BCC address.$mail->setFrom('[email protected]', 'From Name');
: Set sender address and name.$mail->addAddress('[email protected]', 'To Name');
: Set recipient address and name.$mail->Subject = 'PHPMailer BCC Test';
: Set email subject.$mail->Body = 'This is a test of PHPMailer BCC';
: Set email body.$mail->send()
: Send email.
Helpful links
More of Phpmailer
- How to use PHPMailer with PHP 7.4?
- How can I configure PHPMailer to support Polish characters?
- How do I configure the timeout settings for PHPMailer?
- How do I install PHPMailer using Composer?
- How can I use PHPMailer to send emails through Outlook?
- How can I use PHPMailer to send emails through Yandex?
- How do I determine which version of PHPMailer I'm using?
- How can I use PHPMailer without SMTP secure?
- How do I use PHPMailer to send a file?
- How do I set the X-Mailer header using PHPMailer?
See more codes...