Proposal for a possible new PHP5 branch (EDIT | Ok and PHP4)

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Proposal for a possible new PHP5 branch (EDIT | Ok and PHP4)

Post by Chris Corbyn »

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:

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
}
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?
Last edited by Chris Corbyn on Wed Nov 01, 2006 10:46 am, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Who is your target audience? A newbie is just looking for a quick plug and play code or a developer that understands whats going on here? Your answer will pretty much justify whether or not this format is the right direction for Swift.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Jcart wrote:Who is your target audience? A newbie is just looking for a quick plug and play code or a developer that understands whats going on here? Your answer will pretty much justify whether or not this format is the right direction for Swift.
Well yeah, Swift as of now is newbie friendly (I hope). This is a bit more targeted at pure OOP developers.

I could make the underbelly of Swift work in this fashion (even on PHP4, less the exceptions) but keep the interface the same using the "Swift" class and provide an alternative Swift class for the advanced version (or vice versa). Perhaps that would keep everybody happy since non-OO developers who are happy with the existing implementation need not be concious of the re-structuring. I believe I may be able to re-assess some areas to save a bit more memory in the process of doing this too.

It would be a few weeks or so away yet while I get the Java implementation finished off.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I think it's a great idea... :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Just thought I would add, I defiantly do like the adjustments.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

I would aggregate as many of the steps as possible - but maintain the individual breakouts as you described above. It wouldn't be too difficult to keep both sides happy from there (thinking of a Facade more than a big Swift class just duplicating code from the alternate API). Breaking BC is always to drag out a few sore folk ;).
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Ok brilliant, this will happen then :) The biggest change existing users will need to make will be to change "new Swift(...)" to "new SimpleSwift(...)" or something. SimpleSwift just being a wrapper around the new API to provide the same interface as we have now.
Post Reply