Adding a

Hiding the additional recipient from the e-mail header can be done by using the addBcc() method. The addBcc() method acts in the same way as entering an e-mail address into the Bcc: field of the e-mail client. It will send a copy of the e-mail, but not display the additional e-mail addresses that were blind copied to everyone.

Unlike addCc(), addBcc()accepts only a single string parameter representing the e-mail address. Let's update the code in Listing 6-5 and replace all addCc() method calls with addBcc(), as shown in Listing 6-6.

Listing 6-6. Adding Bcc E-mail

* Send email using SMTP Host and BCC.

public function sendEmailWithCopyAction(){

$MailObj->setBodyText($emailMessage); $MailObj->setFrom($fromEmail, $fromFullName); $MailObj->addTo($to);

$MailObj->addBcc('<SECONDARY EMAIL>'); $MailObj->addBcc('<THIRD EMAIL>');

$MailObj->setSubject($subject);

Save the file, replace the markers with valid e-mail addresses you have access to, and run the action by loading the URL http://localhost/email/send-email-with-copy. Once the e-mail arrives to the e-mail address specified in the addTo() method, take a look at the headers. You should not see any additional email addresses used in the addBcc() methods. Now that you understand the basics, you're now ready to send HTML e-mail and attach files to them.

Was this article helpful?

0 0

Post a comment