Page 1 of 2
Version 3 - Release Candidate 1
Posted: Thu Dec 28, 2006 4:42 pm
by Chris Corbyn
This version is now done with. RC2 is available at viewtopic.php?p=351531
/me Rubs eyes in disbelief that it's finally ready
Ok,
this is only for PHP5 right now. Don't worry, that's not a permanent thing, it's just that I've only just finished the entire rewrite and I'm eager to get people playing with the RC alongside the time I'm spending writing the complete documentation and converting it to PHP4.
This release is NOT a modified version of the code in version 2. It's complete rewrite, hence why it's taken so long. It conforms very closely (well, as far as I know, completely) to the RFCs it's supposed to.
DOWNLOAD:
http://www.swiftmailer.org/pre-releases ... rc1.tar.gz [718KB]
http://www.swiftmailer.org/pre-releases ... .0-rc1.zip [914KB]
Documentation is not in the usual place since I'm still working on it using DokuWiki for now:
DOCUMENTATION:
http://www.swiftmailer.org/wikidocs/
I'm quite literally sat here typing that documentation between reading posts here and drinking cups of tea so do forgive the sparseness of them.
The API is
hugely different than it was in version 2 so make sure you look at the examples in the documentation and/or read the API documentation in the "docs" folder of the archive you download.
The EasySwift class should (for the most part) provide all you need to get your existing code working for version 2 and below. Simply replace all occurences of "new Swit(... )" with "new EasySwift( ... )"
When you download the archive and extract it you'll notice that it's several meagbytes in size. Don't worry the actually library is only a few hundred kilobytes, you only need to upload the files in "lib". The other stuff which is making the size bigger is the documentation, smoke tests and unit tests... these are entirely optional parts to upload.
If you have any issues (bugs) or any changes you'd like to see either email me at
chris@w3style.co.uk or post here
The PHP 4 version shouldn't be too far behind since it's pretty much a conversion of the PHP5 code.
Posted: Fri Dec 29, 2006 7:09 pm
by Chris Corbyn
Did anybody download this? I know the PHP5 thing causes a big drop-off in usage but if anybody has and they didn't like what they saw I'd like to know about it before I move from release-candidate to official release.
General opinions on flexibility, intuitiveness and just the overall "feel" of it would be appreciated
I'm going to scrap throwing exceptions on 100% failed sends since they are non-fatal and I can see how that would cause a nuisance.
Posted: Tue Jan 02, 2007 1:00 am
by Hallon
I downloaded it and gave it a very quick look.
How about sending custom newsletters, any built in function? Also, is it possible to add recipients from an array?
I'm not that into OOP (yet), should I maybe use v2 instead?
Thanks,
Anders
Posted: Tue Jan 02, 2007 1:18 am
by Chris Corbyn
Hallon wrote:I downloaded it and gave it a very quick look.
How about sending custom newsletters, any built in function? Also, is it possible to add recipients from an array?
To customize each email, you simply use a foreach() loop and change $message (an object) from inside the loop. Swift_Message handles all the caching on various different levels so this is NOT slow like you might imagine. I decided to offer this flexbility over using something like the template plugin I had previously because it's just more inuitive -- and it allows custom headers too.
Code: Select all
foreach ($recipients as $address => $name)
{
$message->setSubject("Hello $name");
//And whatever else you want to change
$message->send($message, new Swift_Address($address, $name), $from);
}
To send to a list of recipients there is a Swift_RecipientList class which allows you to define To:, Cc:, and Bcc: addresses. Also check out batchSend().
http://www.swiftmailer.org/wikidocs/v3/sending_multiple
http://www.swiftmailer.org/wikidocs/v3/sending_batch
I'm not that into OOP (yet), should I maybe use v2 instead?
Thanks,
Anders
Not at all, just use the EasySwift class rather than the Swift class. EasySwift is basically Swift as it was before

[off-topic]
Posted: Tue Jan 02, 2007 3:45 am
by timvw
Replace all the 'new X' with 'new Y'? I think that's why people invented factories..
Say no to public constructors and add a public static method that returns the instance...
Code: Select all
public class Swift {
public static function GetInstance() { return new EasySwift(); }
}
Et voila, from now on only one change required

Posted: Fri Jan 05, 2007 10:24 am
by Shenz
When will Swiftmailer 3 be released?
Posted: Fri Jan 05, 2007 10:28 am
by Chris Corbyn
Shenz wrote:When will Swiftmailer 3 be released?
I'm having some major issues with the implementation of the PHP 4 version right now (complicated references issues)... I knew I'd possibly have to re-work this particular class for PHP4 though (Swift_Message).
Stepping past that issue I'm not 100% on a date.... I've had virtually 0 feedback on the RC so I have no idea if it's liked, disliked, broken or what
I'll probably just throw it out there and close my eyes in a few weeks at a guess.
Posted: Sun Jan 07, 2007 9:41 am
by Shenz
Hello,
I found some time today to test RC1 to see if it fixes my problem (
viewtopic.php?t=59595).
Please note that I'm not an PHP expert so maybe I'm asking stupid things. What is the difference between the Swift and the EasySwift class? Advantages, disadvantages,... How do I use the EasySwift class?
With Swiftmailer 2 I can send emails without any problem, so I tried to do the same with version 3 and started with the basic example:
Code: Select all
require('misc/Swiftmailer/lib/Swift.php');
require('misc/Swiftmailer/lib/Swift/Connection/SMTP.php');
//Load in the files we'll need
require_once "misc/Swiftmailer/lib/Swift.php";
require_once "misc/Swiftmailer/lib/Swift/Connection/SMTP.php";
//Start Swift
$swift = new Swift(new Swift_Connection_SMTP("smtp.while.be"));
//Create the message
$message = new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "sender@hotmail.com", "recipient@while.be")) echo "Sent";
else echo "Failed";
When trying it returned the following errors:
Code: Select all
Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'The SMTP connection failed to start [smtp.while.be:0]: fsockopen returned Error Number 0 and Error String 'Failed to parse address "smtp.while.be"'' in /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift/Connection/SMTP.php:270 Stack trace: #0 /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift.php(230): Swift_Connection_SMTP->start() #1 /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift.php(97): Swift->connect() #2 /opt/www/username/web/test.while.be/TEST.php(14): Swift->__construct(Object(Swift_Connection_SMTP)) #3 {main} thrown in /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift/Connection/SMTP.php on line 270
What am I doing wrong?
Posted: Sun Jan 07, 2007 11:59 am
by Chris Corbyn
Shenz wrote:Hello,
I found some time today to test RC1 to see if it fixes my problem (
viewtopic.php?t=59595).
Please note that I'm not an PHP expert so maybe I'm asking stupid things. What is the difference between the Swift and the EasySwift class? Advantages, disadvantages,... How do I use the EasySwift class?
With Swiftmailer 2 I can send emails without any problem, so I tried to do the same with version 3 and started with the basic example:
Code: Select all
require('misc/Swiftmailer/lib/Swift.php');
require('misc/Swiftmailer/lib/Swift/Connection/SMTP.php');
//Load in the files we'll need
require_once "misc/Swiftmailer/lib/Swift.php";
require_once "misc/Swiftmailer/lib/Swift/Connection/SMTP.php";
//Start Swift
$swift = new Swift(new Swift_Connection_SMTP("smtp.while.be"));
//Create the message
$message = new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "sender@hotmail.com", "recipient@while.be")) echo "Sent";
else echo "Failed";
When trying it returned the following errors:
Code: Select all
Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'The SMTP connection failed to start [smtp.while.be:0]: fsockopen returned Error Number 0 and Error String 'Failed to parse address "smtp.while.be"'' in /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift/Connection/SMTP.php:270 Stack trace: #0 /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift.php(230): Swift_Connection_SMTP->start() #1 /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift.php(97): Swift->connect() #2 /opt/www/username/web/test.while.be/TEST.php(14): Swift->__construct(Object(Swift_Connection_SMTP)) #3 {main} thrown in /opt/www/username/web/test.while.be/misc/Swiftmailer/lib/Swift/Connection/SMTP.php on line 270
What am I doing wrong?
That's odd. Does the same code work with version 2 on the same server? Ihe error is from PHP's own fsockopen() function... albeit wrapped into an Exception in Swift. It's saying it can't understand the address of the SMTP server "smtp.while.be". I pinged it and it works ok
No, you're not doing anything wrong that would cause this issue. You have got recipient and sender back-to-front though
To use EasySwift you simply follow the Version 2 documentation:
http://www.swiftmailer.org/docs but replace "new Swift" with "new EasySwift". I will write proper documentation for it though.
Anybody else had this fsockopen() error?
~Shenz, what does this code give you (on the same server of course)?
Code: Select all
$sock = fsockopen("smtp.while.be", 25, $errno, $errstr, 30);
var_dump($sock);
echo "<br />Error Number: $errno";
echo "<br />Error Message: $errstr";
Posted: Sun Jan 07, 2007 1:00 pm
by Shenz
d11wtq wrote:Does the same code work with version 2 on the same server?
Yes, it does.
d11wtq wrote:To use EasySwift you simply replace "new Swift" with "new EasySwift".
When using the same example with EasySwift it returns "Fatal error: Cannot redeclare class Swift_Connection_SMTP in /opt/www/warniere/web/test.while.be/misc/Swiftmailer/lib/Swift/Connection/SMTP.php on line 354" (just to inform you)
d11wtq wrote:
~Shenz, what does this code give you (on the same server of course)?
Code: Select all
$sock = fsockopen("smtp.while.be", 25, $errno, $errstr, 30);
var_dump($sock);
echo "<br />Error Number: $errno";
echo "<br />Error Message: $errstr";
Code: Select all
resource(1) of type (stream)
Error Number: 0
Error Message:
Posted: Sun Jan 07, 2007 1:11 pm
by Chris Corbyn
Shenz wrote:d11wtq wrote:Does the same code work with version 2 on the same server?
Yes, it does.
d11wtq wrote:To use EasySwift you simply replace "new Swift" with "new EasySwift".
When using the same example with EasySwift it returns "Fatal error: Cannot redeclare class Swift_Connection_SMTP in /opt/www/warniere/web/test.while.be/misc/Swiftmailer/lib/Swift/Connection/SMTP.php on line 354" (just to inform you)
Oh yeah, good point, I've included those for convenience in the EasySwift class file, although require_once shouldn't ever try to include it again. I'll stop including the connections when I move away from RC. Cheers for the heads-up on that
d11wtq wrote:
~Shenz, what does this code give you (on the same server of course)?
Code: Select all
$sock = fsockopen("smtp.while.be", 25, $errno, $errstr, 30);
var_dump($sock);
echo "<br />Error Number: $errno";
echo "<br />Error Message: $errstr";
Code: Select all
resource(1) of type (stream)
Error Number: 0
Error Message:
Thanks, so that actually connected. I'll do some digging on this. can you just double check that there are no dodgy control characters or something in the string by re-typing that whole line again?

(The line where you call new Swift_Connection_SMTP).
Do the Smoke Tests work?
Posted: Sun Jan 07, 2007 1:13 pm
by Chris Corbyn
Oh hang on, that's odd. It's trying to connect to port 0 in the exception you've got. If you specify port 25 manually does it fix the issue? That's probably my bad
EDIT | In "lib/swift/Connection/SMTP.php"
Change:
Code: Select all
/**
* Try to start the connection
* @throws Swift_Connection_Exception Upon failure to start
*/
public function start()
{
if ($this->port === null)
{
switch ($this->encryption)
{
To:
Code: Select all
/**
* Try to start the connection
* @throws Swift_Connection_Exception Upon failure to start
*/
public function start()
{
if (!$this->port)
{
switch ($this->encryption)
{
I've fixed this in subversion.
Posted: Sun Jan 07, 2007 1:33 pm
by Shenz
d11wtq wrote:Oh hang on, that's odd. It's trying to connect to port 0 in the exception you've got. If you specify port 25 manually does it fix the issue? That's probably my bad

Seems to work for this basic example

Already many thanks!
Now I still have to check if Swiftmailer 3 fixes my "\n" problem
One more question about the use Swiftmailer. Currently I'm using it for sending two confirmation emails after the user registered a product. Is it overkill to use Swiftmailer just for sending 2 emails each time or does it still has advantages?
Posted: Sun Jan 07, 2007 2:11 pm
by Shenz
Seems that when I'm using EasySwift I have no problems with inserting new lines in my messages (see
this topic).
But when using the Swift class in version 3 I have the same problem. Will do some more testing later on this week.
Posted: Sun Jan 07, 2007 3:22 pm
by Chris Corbyn
Shenz wrote:One more question about the use Swiftmailer. Currently I'm using it for sending two confirmation emails after the user registered a product. Is it overkill to use Swiftmailer just for sending 2 emails each time or does it still has advantages?
With small numbers of emails the advantages you get from using swift are basically the way it composes messages with headers just like a real email client.
Shenz wrote:Seems that when I'm using EasySwift I have no problems with inserting new lines in my messages (see
this topic).
But when using the Swift class in version 3 I have the same problem. Will do some more testing later on this week.
That's too wierd, EasySwift doesn't do any processing of the text, it only passes the message along to Swift as a Swift_Message object
