I'm trying now to combine two different turorials, but somehwhere in the middle I get stuck :S
I'd like to send a batch of personalized e-mail messages, but I also want the message to be in html format.
This is what I got so far. It sends the messages perfectly, but doesn't personalize them.
Code: Select all
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Plugin/Decorator.php";
$log =& Swift_LogContainer::getLog();
$log->setLogLevel(4);
//Instantiate Swift as usual
$smtp =& new Swift_Connection_SMTP("domain.tld");
$smtp->setUsername("****");
$smtp->setPassword("****");
$swift =& new Swift($smtp);
$message =& new Swift_Message($_POST['subject']);
$template = '<html><body><img src="'.$message->attach(new Swift_Message_Image(new Swift_File("./images/header.jpg"))).'" />';
$template .= $_POST['content'];
$template .= '</body></html>';
$message->attach(new Swift_Message_Part($template, "text/html"));
//Specify the list of replacements as a 2-d array
$replacements = array(
"foo@bar.com" => array("{firstname}" => "Foo", "{lastname}" => "Bar"),
"bar@foo.com" => array("{firstname}" => "Bar", "{lastname}" => "Foo"),
);
//Load the plugin with these replacements
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
//Send messages
$recipients =& new Swift_RecipientList();
$recipients->addTo("foo@bar.com");
$recipients->addTo("bar@foo.com");
//Send with batchSend()
$swift->batchSend($message, $recipients, "my@domain.com");
$swift->disconnect();
echo $log->dump(true);
CheerMichiel