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

The setReturnPath() 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

Even though Swift Mailer has many methods that allow you to manipulate MIME headers in useful and creative ways, in this last section of the tutorial I’m going to show you the use of only one. Called “setReturnPath(),” it comes in handy for assigning a value to the “Return-Path” header.

Since the method is extremely simple to utilize, the following sample script should dissipate any doubts that you may have regarding its use:  

// example on sending a basic email message with Swift Mailer (uses the setReturnPath() 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', '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')

->setReturnPath('alejandro@domain.com');

 

// send the email message

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

{

echo 'The message was sent successfully!';

}

else

{

echo 'Error sending email message';

}

As shown above, the utilization of the “setReturnPath()” method offers no major difficulties, and it’s only a small example of how easy it is to manipulate MIME headers with Swift Mailer. Of course, there’s the possibility that you may want to look at other methods that directly affect other popular MIME headers, so I recommend that you read the library’s official documentation.

Final thoughts

Sad but true, we’ve come to the end of this series. But I hope you enjoyed reading it as much as I did writing it. The series attempted to introduce you as gently as possible to using the most important methods provided by Swift Mailer, but the library has much more to offer; it boasts plenty of features that haven’t been covered here.

So, if you’re looking for a complete guide that covers all of the aspects of this email package, the best place to look is undoubtedly its official documentation, which not only is thorough, but very easy to digest.

See you in the next PHP development tutorial!



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