PHP Classes

File: test_smarty_personalized_mailing.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Manuel Lemos  >  MIME E-mail message sending  >  test_smarty_personalized_mailing.php  >  Download  
File: test_smarty_personalized_mailing.php
Role: Example script
Content type: text/plain
Description: Test script for sending personalized bulk mailings using templates using the Smarty engine to compose HTML and plain text alternative parts of the messages.
Class: MIME E-mail message sending
PHP mailer to compose and send MIME messages
Author: By
Last change: Fixed minor error in commented example code.
Date: 4 years ago
Size: 6,612 bytes


Class file image Download
 * test_smarty_personalized_mailing.php
 * @(#) $Header: /opt2/ena/metal/mimemessage/test_smarty_personalized_mailing.php,v 1.5 2005/02/16 04:04:03 mlemos Exp $


 * Include Smarty template engine class. Make sure the class file is in
 * your include path.

 * Assign the $from_name and $from_address to your real sender name and
 * address or else the message may not be accepted.

/* Define recipient personalization data. Change this before testing. */
"name"=>"Peter Gabriel",
"name"=>"Paul Simon",
"name"=>"Mary Chain",

$subject="Testing Manuel Lemos' MIME Email composition PHP class for sending personalized bulk mail using HTML and text template with the Smarty engine";

$email_message=new email_message_class;

     * For faster queueing use qmail...
     * require_once("qmail_message.php");
     * $email_message=new qmail_message_class;
     * or sendmail in queue only delivery mode
     * require_once("sendmail_message.php");
     * $email_message=new sendmail_message_class;
     * $email_message->delivery_mode=SENDMAIL_DELIVERY_QUEUE;
     * Always call the SetBulkMail function to hint the class to optimize
     * its behaviour to make deliveries to many users more efficient.


     * Set the Return-Path header to define the envelope sender address to which bounced messages are delivered.
     * If you are using Windows, you need to use the smtp_message_class to set the return-path address.

     * If you are not going to personalize the message body for each recipient,
     * set the cache_body flag to 1 to reduce the time that the class will take
     * to regenerate the message to send to each recipient

     * Lets use two distinct Smarty objects for composing the HTML and text
     * parts and avoid the need to re-assign constant values when switching
     * contexts.
$html_smarty=new Smarty;
$text_smarty=new Smarty;
    || !
"Please copy the template file templates/".$template." to your Smarty templates directory.\n";

/* Create empty parts for the parts that will be personalized for each recipient.
     * HTML message values should be escaped with HTMLEntities().


 * It is strongly recommended that when you send HTML messages,
 * also provide an alternative text version of HTML page,
 * even if it is just to say that the message is in HTML,
 * because more and more people tend to delete HTML only
 * messages assuming that HTML only messages are spam.

 * Multiple alternative parts are gathered in multipart/alternative parts.
 * It is important that the fanciest part, in this case the HTML part,
 * is specified as the last part because that is the way that HTML capable
 * mail programs will show that part and not the text version part.

/* Iterate personalization for each recipient. */

/* Personalize the recipient address. */

/* Do we really need to personalize the message body?
         * If not, let the class reuse the message body defined for the first recipient above.
             * Create a personalized body parts, either HTML and text
             * alternative parts.

$first_name=strtok($to_name," ");


/* Make the personalized replace the initially empty HTML part */


/* Make the personalized replace the initially empty text part */

/* Send the message checking for eventually acumulated errors */

/* When you are done with bulk mailing call the SetBulkMail function
     * again passing 0 to tell the all deliveries were done.

"Error: $error\n";