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

Review: working with carbon copies - 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

It would be helpful to reintroduce the practical example developed in the preceding article of this series. In it, I discussed how to take advantage of the "setCc()" method provided by the Swift Mailer library to attach a carbon copy to a simple email message.

Below I listed the full source code corresponding to the example, so you can study it closely. Here it is:

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

 

// 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'))

// specify the Cc argument

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

// build the body part of the message

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

 

// send the email message

if ($mailer->send($message))

{

echo 'The message was sent successfully!';

}

else

{

echo 'Error sending email message';

}

Certainly, you'll have to agree with me that sending a carbon copy along with a plain-text email message is a simple process reduced to specifying the names and email addresses of the respective recipients via the "setTo() and "setCc()" methods of the "Swift_Message" class.

Finally, once the complete message has been created, the already familiar "send()" method takes care of sending the corresponding copies to the appropriate recipients, as has been clearly illustrated by the above code sample.

So far, everything looks good, since at this point you hopefully recalled how to use Swift Mailer to handle carbon copies of an email message in a truly simple manner. So, what's the next step to take? Well, as I mentioned in the introduction, the library obviously allows us to work with blind carbon copies as well by using another intuitive method, not surprisingly called "setBcc()."

Thus, in the section to come I'm going to take a closer look at this brand new method, so you can learn how to use it very quickly.

Now, click on the link displayed below and proceed to read the next segment. I'll be there, waiting for you.



 
 
>>> 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: