Home arrow PHP arrow Page 3 - Swift Mailer's Batchsend Method and Other Features

The batchSend() method - PHP

Welcome to the final part of a ten-part series that shows you how to use the Swift Mailer library to build email applications. This final part of the series will explain how to use the batchsend() method, and how to specify the Return-path MIME header within emails.

TABLE OF CONTENTS:
  1. Swift Mailer's Batchsend Method and Other Features
  2. Review the setDisposition() and embed() methods
  3. The batchSend() method
  4. The setReturnPath() method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
March 01, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As I expressed in the introduction, the Swift Mailer library includes another method that allows you to send email messages, but in a slightly different way. What does it do differently from its counterpart “send()”? It'll simply send a completely separate message to each recipient specified within the “To” header. This means the targeted recipient will see only their email address, which can be really useful in certain situations.

To show how to use this method, below I modified the script developed in the previous section, so you can grasp how it works. Here it is:

// example on sending a basic email message with Swift Mailer (uses the batchSend() 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('susan@domain.com', 'mary@domain.com' => 'Hello from here'))

// build the body part of the message

->setBody('I am sending an email message with the cool Swift Mailer library');

 

// send the email message

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

{

echo 'The message was sent successfully!';

}

else

{

echo 'Error sending email message';

}

Even though the script that sends the above email looks nearly identical to the previous ones, in this case my friends Susan and Mary will see only their email addresses when receiving the message (and hopefully, this will make them feel a bit less jealous, too).

Having already spotted the subtle differences between using the “send()” and “batchSend()” methods, it’s time for the last part of this tutorial. I’ll be coding a final script, which will show how to specify a return path when sending emails.

Please go ahead and read the last section.



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