Proposal for a possible new PHP5 branch (EDIT | Ok and PHP4)
Posted: Wed Nov 01, 2006 10:27 am
Since this is a fair bit different (and more complex) I may just release it under a different branch and keep the existing Swift under development as-is. I could of course provide yet another compat file to wrapper it all up.
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:
I'm aware it's a bit of a steep learning curve from Swift as it is now but in terms of modularity it's heaps better with all Message components extending a Mime class, Recipients contained into their own groups, the ability to loop with an already built (and compiled) message etc.
Just wanted to pick your brains really?
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?