Home arrow PHP arrow Page 3 - Sending Blind Carbon Copies with Swift Mailer

Using the setBcc() method - PHP

This fifth part of the series expands your background in the Swift Mailer library. You will learn how to use it for sending blind carbon copies of a basic email message to a predefined recipient. The process is as simple as using its "setBcc()" method.

TABLE OF CONTENTS:
  1. Sending Blind Carbon Copies with Swift Mailer
  2. Review: working with carbon copies
  3. Using the setBcc() method
  4. The complete script for sending multiple email copies
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
February 18, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As I said in the section that you just read, the Swift Mailer library permits you to send blind carbon copies of an email message in a very simple manner, as one would normally expect from a high-quality package. Performing this task is as easy as invoking a new method called "setBcc()" with the email address and name of the corresponding recipient of the copy.

However, the best way to understand how this handy method works is by example, so below I coded one for you. Have a look at it:

// example on sending a basic email message with Swift Mailer (uses the 'setCc() and 'setBcc() methods')

 

// include required files

require_once 'lib/swift_required.php';

 

// create the mail transport using the 'newInstance()' method

$transport = Swift_SmtpTransport::newInstance('mail.domain.com', 25)

->setUsername('alejandro@domain.com')

->setPassword('password');

 

// create the mailer using the 'newInstance()' method

$mailer = Swift_Mailer::newInstance($transport);

 

// create a simple message using the 'newInstance()' method

$message = Swift_Message::newInstance()

// specify the subject of the message

->setSubject('Testing Swift Mailer')

// specify the From argument

->setFrom(array('alejandro@domain.com' => 'Alejandro Gervasio'))

// specify the To argument

->setTo(array('john@domain.com' =>' John Doe'))

->setCc(array('mary@domain.com' => 'Mary Jackson'))

->setBcc(array('susan@domain.com' => 'Susan Norton'))

// build the body part of the message

->setBody('Hey, how are you? I am sending you a message with the cool Swift Mailer library');

Didn't I tell you that attaching a blind carbon copy to an email message was a breeze with Swift Mailer? Well, the above example proves that I was right. As you can see, before building the body part of the message, the "setBcc()" method is used for specifying the email address and the name of the recipient of the copy, which is very similar to the process performed when sending normal copies.

But, wait a minute! The previous example is actually is incomplete. It's not really sending any messages, because the corresponding "send()" method is not invoked at any point. So, in the final section I'm going to add to the script that missing part, thus completing the development of this example.

If you want to see how the example will look when finished, simply go ahead and read the following section. It's only one click away.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: