replacements - body find replace

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
tgkprog
Forum Newbie
Posts: 2
Joined: Mon Jul 07, 2008 5:02 am

replacements - body find replace

Post by tgkprog »

general - using to send email to everyone who has signed up for a mailer form a website
but we send diff emails according to number of days since sign up
have many receipient lists, add to diff list , then batch send
----

Replacements class to customize subjecct and body like {name_f} with actual name :-

Code: Select all

class Replacements extends Swift_Plugin_Decorator_Replacements {
    function getReplacementsFor($address) {
        $query = "select id as `{id}`,
                  login as `{login}`,
                  email as `{email}`,
                  name_f as `{name_f}`,
                  name_l as `{name_l}`,
                  waiora_id as `{waiora_id}`,
                  phone as `{phone}`,
                  lead_name as `{lead_name}`,
                  lead_email as `{lead_email}`,
                  lead_phone as `{lead_phone}`,
                  lead_address as `{lead_address}`,
                  lead_city as `{lead_city}`,
                  lead_state as `{lead_state}`,
                  lead_zip as `{lead_zip}`
                  from leads where lead_email = '" . mysql_real_escape_string($address) . "' ";
                  //and (joined is null or joined = false)
 
        $result = mysql_query($query);
                  global $dbg;
                  //if($dbg < 5)
                  {
                    echo "  q $query [err :" . mysql_errno(). "] " . mysql_error(). " <br><br>\n\n";;
                    $dbg++;
                  }
        if (mysql_num_rows($result) > 0)
        {
            return mysql_fetch_assoc($result);
        }
    }
}

as you can see i'm echo " q $query" - but i notice that this is called only one time per message and not once per receipient

is this the way its supposed to work?

using batch send

partial code

Code: Select all

$swift = new Swift(...);

//different messages for different days since sign up

$ztl_message1 = new Swift_Message($ztl_subject1, $ztl_body1);
$ztl_message2 = new Swift_Message($ztl_subject2, $ztl_body2);
$ztl_message3 = new Swift_Message($ztl_subject3, $ztl_body3);
//...
//Create recipient objects
$ncd_recipients1 = new Swift_RecipientList();
$ncd_recipients2 = new Swift_RecipientList();


//sql loop
//Create recipient objects
$ncd_recipients1 = new Swift_RecipientList();
{
//get from DB
//add to correct receipeint list 
// Send mail to leads
while ($row = mysql_fetch_assoc($result)) {
   $email = $row['lead_email'];
   $added = $row['added'];
   $hide = $row['hide'];
   $source = $row['source'];

   $days = (time() - $added)/86400;
	echo "\n<br>eml $email hid $hide s $source  \n<br>";

// Check to see which site the lead opted in from
if (($source == 0) && ($hide == 0)) {


// Check to see how long it has been since they signed up and send the corresponding
// message

   if (($days >= $m9) && ($days < ($m9 + 1))) {
      $ncd_recipients9->addTo($email);
if (($days >= $m9) && ($days < ($m9 + 1))) {
      $ncd_recipients9->addTo($email);

   } elseif (($days >= $m8) && ($days < ($m8 + 1))) {
      $ncd_recipients8->addTo($email);

   } elseif (($days >= $m7) && ($days < ($m7 + 1))) {
      $ncd_recipients7->addTo($email);//....
}


$from_ncd = new Swift_Address("response@aa.com");
$from_ztl = new Swift_Address("response@aaa.com");

//Send messages
$num_sent = $swift->batchSend($ncd_message1, $ncd_recipients1, $from_ncd);
$num_sent = $num_sent + $swift->batchSend($ncd_message2, $ncd_recipients2, $from_ncd);
//....
$num_sent = $num_sent + $swift->batchSend($ztl_message1, $ztl_recipients1, $from_ztl);
$num_sent = $num_sent + $swift->batchSend($ztl_message2, $ztl_recipients2, $from_ztl);

but i notice that my Replacement class is not called for each receipient that the mail is sent to

is there a way to call it with for each?
Post Reply