Decorating plugin not decorating.

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
gamak
Forum Newbie
Posts: 8
Joined: Tue Feb 10, 2009 7:24 pm

Decorating plugin not decorating.

Post by gamak »

Ok so the script sends email out, the only problem is that it doesn't replace any text. The emails come through looking like
-------------------
Hey {name}
Hows it going.
-------------------

Code: Select all

 
<?php error_reporting(E_ALL); ini_set('display_errors', true); ?>
<?php
require_once "/var/www/vhosts/bpmgpublishingsystem.com/httpdocs/swift/lib/Swift.php";
require_once "/var/www/vhosts/bpmgpublishingsystem.com/httpdocs/swift/lib/Swift/Connection/SMTP.php";
require_once "/var/www/vhosts/bpmgpublishingsystem.com/httpdocs/swift/lib/Swift/Plugin/Decorator.php";
//// Get data/////    
$from = $_POST['from'];   
$email_list = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['message']; 
 
//// Seperate the email Data/////////
$first_name = array();
$last_name = array();
$email_address = array();
$addys = preg_split('/\s*;\s*/', $email_list);
foreach($addys as $add)
{
   preg_match('/^(.+\s)?([^\s<]+)\s*<([^>]*)>/', $add, $matches);
   $first_name[] = $matches[1];
   $last_name[] = $matches[2];
   $email_address[] = $matches[3];
}
///////////////// Array combine ////////////////////////////// 
 $replacements = array(); 
 $combo = array_combine ($email_address, $first_name); 
/////////////////////Build Replacements array ///////////////////////////////////
 $string = '{name}'; 
 foreach ($combo as $email_a => $lname)
       {
         $replacements[] = array($email_a => array($string => $lname)); 
       }  
///////////////////////////Email Sending///////////////////////////////////////////
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
$message =& new Swift_Message($subject, $msg);
$recipients =& new Swift_RecipientList();
 foreach ($email_address as $value) 
  {
  $recipients->addTo($value);
  } 
//NOTE that Cc and Bcc recipients are IGNORED in a batch send
 //////////replacer plugin/////////////////
 $swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
 /////////////////////////////////////////////////////
 if ($swift->batchSend($message, $recipients, "sean@orcacommunications.com"))
    { 
        echo "Message Sent"; 
    } 
    else 
    { 
        echo "Message Failed"; 
    }       
 ?>
 
Any one know what I'm doing wrong?
Post Reply