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!
blog comments powered by Disqus |
|
|
|
|
|
|
|