Decorator not working in multipart email (plain text/html)?

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
snursita
Forum Newbie
Posts: 8
Joined: Thu Jul 12, 2007 2:58 am

Decorator not working in multipart email (plain text/html)?

Post by snursita »

Dear All, I have used Decorator plugin in HTML mail before and it worked perfectly. Today I'm writing a new code to use Decorator in multipart email (plain & HTML) but it's not working? Please help, what did I do wrong? Thanks!

I'm using Swift 3.3.1 on PHP 4.

Code: Select all

 
// GET MANAGER SIGNATURES
$sig_pm = file_get_contents("signature_pm.txt");
$sig_res = file_get_contents("signature_res.txt");
$sig_trep = file_get_contents("signature_trep.txt");
 
// SETTING UP RECIPIENTS & PERSONALIZATIONS
$file = "Announcement1.csv";
$lines = @file($file);
$replacements = array();
$recipients =& new Swift_RecipientList();
foreach ($lines as $line) {
  list(
    $division, 
    $name, 
    $company, 
    $building, 
    $street, 
    $city, 
    $zip,
    $email
  ) = explode(";", $line);
  $signature = "";
  switch($division) {
    case "PM": 
      $signature = $sig_pm;
      break;
    case "RES";
      $signature = $sig_res;
      break;
    case "TREP";
      $signature = $sig_trep;
      break;
  }
  $clientdetails = $name . "<br>" . $company . "<br>" . $building . "<br>" . $street . "<br>" . $city . " " . $zipcode . "<br>";
  $recipients->addTo($email);
  $replacements[$email] = array("{CLIENTDETAILS}"=>$clientdetails,"{SIGNATURE}"=>$signature);
}
 
// SETTING UP CONTENTS
$content_text = file_get_contents("announce.txt");
$content = file_get_contents("emailannouncement.html");
$content = str_replace("[ANNOUNCEIMG]", "announce.jpg", $content);
$subject = "PT. Koll IPAC Consolidation News";
 
// CREATE MAIL CONNECTION
$smtp_path = "mail.tld"; 
$smtp =& new Swift_Connection_SMTP($smtp_path, 25);
$smtp->setTimeout(60);
$smtp->setUsername("me@mail.tld");
$smtp->setPassword("mypass");
$swift =& new Swift($smtp);
$swift->attachPlugin(new Swift_Plugin_AntiFlood(50, 10), "anti-flood"); 
$swift->attachPlugin(new Swift_Plugin_FileEmbedder(), "file_embedder");
 
$log =& Swift_LogContainer::getLog();
$log->setLogLevel(SWIFT_LOG_FAILURES);
$log->setMaxSize(50);
 
$sender = new Swift_Address("me@mail.tld", "Me");
$replyto = new Swift_Address("me@mail.tld", "Me");
$swiftmessage =& new Swift_Message();
$swiftmessage->attach(new Swift_Message_Part($content_text, 'text/plain'));
$swiftmessage->attach(new Swift_Message_Part($content, 'text/html'));
$swiftmessage->setReplyTo($replyto);
$swiftmessage->setSubject($subject);
 
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
 
// SEND!
if ($swift->batchSend($swiftmessage, $recipients, $sender))
{
  echo "<br>Message sent!!";
}
else
{
  $logmessage = $log->dump(true);
  echo "<br>".$logmessage;
  echo "<br><font color=red>Sorry, the system failed to send the email notification</font>. Please notify the System Administrator. Thank you.";
}
$swift->disconnect();
 
This is emailannouncement.html

Code: Select all

 
<html>
<head>
<style>
<!--
  BODY{font-size:10pt;font-family:Arial;color:black;}
-->
</style>
</head>
<body>
{CLIENTDETAILS}
<br>
<img src="[ANNOUNCEIMG]" alt="PT. Koll IPAC Consolidation News" />
<br>
{SIGNATURE}
</body>
</html>
 
This is announce.txt

Code: Select all

 
{CLIENTDETAILS}
 
PT. Koll IPAC is now in the process of consolidating its operations with those of PT. Colliers International Indonesia (CII). Accordingly, the lines of business at PT Koll IPAC (Koll) and Koll Residential are taking on the Colliers International brand. 
 
The 'new' CII will benefit from the knowledge, experience and resources found throughout Colliers International’s global network of over 10,000 professionals in 275 offices spread throughout 57 countries around the world.
 
The integration of the teams of professionals of Koll and CII (and its valuation arm, PT Penilai), will result in the largest full service international property consultant in Indonesia, with approximately 250 employees and 13 property service specializations.
 
Advisory: Research Consultancy Valuation
Transactions: Office - Tenant/Investor Representation Services, Office - Property Representation Services Industrial Services, Retail Services Hotels & Leisure Services Residential - Tenant/Investor Representation Services Residential - Property Representation Services
Management: Project Management Services, Facility Management Services, Property Management Services
 
Locations:
World Trade Centre, 10th Floor
Jalan Jenderal Sudirman Kav 29-31
Jakarta 12920 Indonesia
Phone: 62 21 521 1400
 
Wisma 46, Kota BNI, 31st Floor, Suite 3108,
Jalan Jenderal Sudirman Kav 1,
Jakarta 10220 Indonesia
Phone: 62 21 574 9828
 
Residential / Facility Management
Jalan Prapanca Raya No. 32 - 34
Jakarta Selatan 12160 Indonesia
Phone: 62 21 7279 4868
 
{SIGNATURE}
 
Post Reply