I'm growing ever concious of the size of the Swift.php file and could do with some major refactoring in the area of Message composition mostly among other things.
My initial thoughts (spurred from the Java mailer I'm building) are something like this:
Code: Select all
<?php
try {
//Create a new instance of the mailer using whatever connection
$mailer = new Swift(new Swift_SMTP("host.tld"));
//Start composing a message (caching can occur inside the message object)
$message = new Swift_Message("My Subject");
$message->setFrom(new Swift_Address("Chris", "chris@w3style.co.uk"));
//Build the message up
$part1 = new Swift_Part("Foobar", "text/html");
$message->add($part1);
$part2 = new Swift_Part("Foobar plain");
$message->add($part2);
$att = new Swift_Attachment("/home/d11twq/mydocument.pdf");
$att->setContentType("application/pdf");
$message->add($att);
//Send to a list of addresses (Swift_Address is a single address)
$recipients = new Swift_AddressList();
$recipients->addTo("Chris", "chris@w3style.co.uk");
$recipients->addTo("Joe", "joe@bloggs.com");
$recipients->addCc("Jim", "jim@henderson.tld");
$recipients->addBcc("some@address.com");
//Deliver the message to the recipients
$mailer->send($message, $recipients);
$mailer->close();
} catch (Swift_ConnectionException $e) {
//handle failed connection
} catch (Swift_MimeException $e) {
//handle failed message building
} catch (Swift_IOException $e) {
//handle failed command
}Just wanted to pick your brains really?