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 can I configure PHPMailer to support Polish characters?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer to attach a ZIP file?
- How can I use PHPMailer in Yii 1?
- How can I set up PHPMailer to use Zimbra SMTP?
- How can I use PHPMailer without SMTP secure?
- How do I use PHPMailer to send a file?
- How can I send emails using PHPMailer without using SMTP?
- How do I use PHPMailer to encode emails in UTF-8?
- How to use PHPMailer with PHP 7.4?
See more codes...