Since it's been requested, here's a few side-by-side's against PHPMailer.
Some of these examples are only available in 1.1 due for release in a couple of days.
It's the first time I've done this actually so pretty interesting

I'm aware of the fact that the Swift code looks tighter - I've just laid it out the way I code, copy and past and muck around if you want.
---------------------
Sending a plain email over SMTP:
In PHPMailer
Code: Select all
<?php
require('class.phpmailer.php');
$mail = new PHPMailer;
$mail->From = 'someone@tld';
$mail->FromName = 'Someone';
$mail->Host = 'smtp.host.tld';
$mail->Mailer = 'smtp';
$mail-Subject = 'Some subject';
$mail->Body = 'The email body';
$mail->AddAddress('recipient@tld', 'Recipient Name');
if (!$mail->Send()) echo 'Not sent!';
$mail->ClearAddresses();
?>
In Swift
Code: Select all
<?php
require('Swift.php');
require('Swift/Swift_SMTP_Connection.php');
$mail = new Swift(new Swift_SMTP_Connection('smtp.host.com'));
if (!$mail->send(
'"Recipient Name" <recipient@tld>',
'"Someone" <someone@tld>',
'Some subject',
'This is the body')) echo 'Not sent!';
?>
-------------------------------
Sending a mail with a HTML part and a plain text part
PHPMailer
Code: Select all
<?php
require('class.phpmailer.php');
$mail = new PHPMailer;
$mail->From = 'someone@tld';
$mail->FromName = 'Someone';
$mail->Host = 'smtp.host.tld';
$mail->Mailer = 'smtp';
$mail->IsHTML();
$mail-Subject = 'Some subject';
$mail->Body = '<em>HTML</em> part';
$mail->AltBody = 'Plain part';
$mail->AddAddress('recipient@tld', 'Recipient Name');
if (!$mail->Send()) echo 'Not sent!';
$mail->ClearAddresses();
?>
Swift
Code: Select all
<?php
require('Swift.php');
require('Swift/Swift_SMTP_Connection.php');
$mail = new Swift(new Swift_SMTP_Connection('smtp.host.com'));
$mail->addPart('Plain part');
$mail->addPart('<em>HTML</em> part', 'text/html');
if (!$mail->send(
'"Recipient Name" <recipient@tld>',
'"Someone" <someone@tld>',
'Some subject')) echo 'Not sent!';
?>
----------------------------------------
Sending an email to 4 people independently:
In PHPMailer
Code: Select all
<?php
require('class.phpmailer.php');
$mail = new PHPMailer;
$recipients = array('one@tld', 'two@tld', 'three@tld', 'four@tld');
$mail->From = 'someone@tld';
$mail->FromName = 'Someone';
$mail->Host = 'smtp.host.tld';
$mail->Mailer = 'smtp';
$mail-Subject = 'Some subject';
$mail->Body = 'Body';
foreach ($recipients as $address)
{
$mail->AddAddress($address);
if (!$mail->Send()) echo 'Not sent!';
$mail->ClearAddresses();
}
?>
Swift
Code: Select all
<?php
require('Swift.php');
require('Swift/Swift_SMTP_Connection.php');
$mail = new Swift(new Swift_SMTP_Connection('smtp.host.com'));
$recipients = array('one@tld', 'two@tld', 'three@tld', 'four@tld');
if (!$mail->send(
$recipients,
'"Someone" <someone@tld>',
'Some subject',
'Body')) echo 'Not sent!';
?>
--------------------------------
Sending an attachment:
PHPMailer
Code: Select all
<?php
require('class.phpmailer.php');
$mail = new PHPMailer;
$file = '../files/myimage.jpg';
$filename = 'My Image.jpg';
$mail->From = 'someone@tld';
$mail->FromName = 'Someone';
$mail->Host = 'smtp.host.tld';
$mail->Mailer = 'smtp';
$mail-Subject = 'Some subject';
$mail->Body = 'Body';
$mail->AddAddress('recipient@tld', 'Recipient Name');
$mail->AddAttachment($file, $filename);
if (!$mail->Send()) echo 'Not sent!';
$mail->ClearAddresses();
$mail->ClearAttachments();
?>
Swift
Code: Select all
<?php
require('Swift.php');
require('Swift/Swift_SMTP_Connection.php');
$mail = new Swift(new Swift_SMTP_Connection('smtp.host.com'));
$file = '../files/myimage.jpg';
$filename = 'My Image.jpg';
$mail->addPart('Body');
$mail->addAttachment(file_get_contents($file), $filename);
if (!$mail->send(
'"Recipient Name" <recipient@tld>',
'"Someone" <someone@tld>',
'Some subject')) echo 'Not sent!';
?>
---------------------------------------------
Sending mail with an inline image:
PHPMailer
Code: Select all
<?php
require('class.phpmailer.php');
$mail = new PHPMailer;
$cid = 'abcdefg123456';
$image = '../files/myimage.jpg';
$mail->IsHTML();
$mail->From = 'someone@tld';
$mail->FromName = 'Someone';
$mail->Host = 'smtp.host.tld';
$mail->Mailer = 'smtp';
$mail-Subject = 'Some subject';
$mail->Body = '<strong>So here is where we went!</strong><br />
<img src="cid:'.$cid.'" alt="Somewhere" /><br />
Pretty nice eh?';
$mail->AddEmmbeddedImage($file, $cid);
$mail->AddAddress('recipient@tld', 'Recipient Name');
if (!$mail->Send()) echo 'Not sent!';
$mail->ClearAddresses();
$mail->ClearAttachments();
?>
Swift
Code: Select all
<?php
require('Swift.php');
require('Swift/Swift_SMTP_Connection.php');
$mail = new Swift(new Swift_SMTP_Connection('smtp.host.com'));
$image = '../files/myimage.jpg';
$mail->addPart('<strong>So here is where we went!</strong><br />
<img src="'.$mail->addImage($image).'" alt="Somewhere" /><br />
Pretty nice eh?', 'text/html');
if (!$mail->send(
'"Recipient Name" <recipient@tld>',
'"Someone" <someone@tld>',
'Some subject')) echo 'Not sent!';
?>
-----------------------------------------
Relaying mail via Gmail servers (TLS encryption)
PHPMailer
Code: Select all
<?php
/** Forget it - TLS is not supported **/
?>
Swift
Code: Select all
<?php
require('Swift.php');
require('Swift/Swift_SMTP_Connection.php');
//I had this automated but it was flaky - I'll try to remove the need to do this again
$mail = new Swift(new Swift_SMTP_Connection('smtp.gmail.com', false, SWIFT_TLS));
$mail->authenticate('user@gmail.com', 'pass');
if (!$mail->send(
'"Recipient Name" <recipient@tld>',
'"Someone" <someone@tld>',
'Some subject',
'The body')) echo 'Not sent!';
?>
Haven't had time to benchmark yet... was this what you were looking for though?