PHP Classes

AlternativeMultipart-Messages with personalized Bodyparts

Recommend this page to a friend!

      MIME E-mail message sending  >  MIME E-mail message sending package blog  >  How Can PHP Send Emai...  >  All threads  >  AlternativeMultipart-Messages with...  >  (Un) Subscribe thread alerts  
Subject:AlternativeMultipart-Messages with...
Summary:how to create and replace personalized bodyparts in Bulkmail
Messages:3
Author:Horst Nogajski
Date:2008-07-01 18:43:02
Update:2008-07-02 19:44:31
 

  1. AlternativeMultipart-Messages with...   Reply   Report abuse  
Picture of Horst Nogajski Horst Nogajski - 2008-07-01 18:43:02
Hi all,

have used the classes a long time for sending my newsletters in Plain/Text with personalized Bodyparts via SMTP. Now I want to switch to AlternativeMultipart-Messages (HTML with Inline-Images).

In the old Script I used this code like in package examples:

// Create replacementpart for PersonalizedBulkmails
$message=$hn->file2string($MAIL_TEMPLATE);
$email_message->CreateQuotedPrintableTextPart($message,"",$text_part);
$email_message->AddPart($text_part);

$email_message->SetBulkMail(1);

... and while looping through the recipients:
/* Create a personalized body part. */
$email_message->CreateQuotedPrintableTextPart($email_message->WrapText($body),"",$recipient_text_part);
/* Make the personalized replace the initially empty part */
$email_message->ReplacePart($text_part,$recipient_text_part);


Now, in the new script, I have to create an alternative PlainText-Body additionally to the HTML-Body with inline-images. So, haven't checked out how I have to do the replacement-parts in both bodies (plain and html) to personalize them.

New Scriptcode, to create a single AlternativeMultipart-Mimemessage works fine:

$HTML_TEMPLATE = file_get_contents('./briefpapier_01.html');
$HEADER_LOGO = embedd_image(dirname(__FILE__).'/nogajski_logo.jpg', $part_cid_01);

$HTML_BODY = str_replace(array('[HEADER_LOGO]','[BODY]','[FOOTER]'), array($HEADER_LOGO,$BODY,$FOOTER),$HTML_TEMPLATE);
$TEXT_BODY = isset($TEXT_BODY) ? $TEXT_BODY : $email_message->WrapText(trim(strip_tags($BODY."\r\n".$FOOTER)));

// create alternative Bodyparts
$email_message->CreateQuotedPrintableTextPart($TEXT_BODY,'iso-8859-1',$part_body_text);
$email_message->CreateQuotedPrintableHTMLPart($HTML_BODY,'iso-8859-1',$part_body_html);
$a = array($part_body_text,$part_body_html);
$email_message->CreateAlternativeMultipart($a,$part_body_alternative);

// add combined Bodypart and related Images
$a = array($part_body_alternative,$part_cid_01);
$email_message->AddRelatedMultipart($a);


Did someone know how to do the replacement and can tell me please?

Regards, Horst

  2. Re: AlternativeMultipart-Messages with...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-07-01 19:55:14 - In reply to message 1 from Horst Nogajski
If you do not change the images, all you need to do is to use the cid:image_id convention in the link URL in the HTML part. Other than that, the ReplacePart function will take care of using the new personalized text or HTML parts.

  3. Re: AlternativeMultipart-Messages with...   Reply   Report abuse  
Picture of Horst Nogajski Horst Nogajski - 2008-07-02 19:44:31 - In reply to message 2 from Manuel Lemos
Hi Manuel,

many thanks for the quick reply. (And also for the great classes ;-) )

Yes, it works perfectly, because the images are not personalized, so I have only to create the two personalized Bodyparts and replace the initially added parts with them.


/* Create personalized body parts */
$part_body_html_personalized = str_replace($search,$replace,$HTML_BODY);
$part_body_text_personalized = str_replace($search,$replace,$TEXT_BODY);
$email_message->CreateQuotedPrintableHtmlPart($part_body_html_personalized,'iso-8859-1',$part_body_html_personalized_id);
$email_message->CreateQuotedPrintableTextPart($part_body_text_personalized,'iso-8859-1',$part_body_text_personalized_id);

/* Make the personalized replace the initially empty parts */
$email_message->ReplacePart($part_body_html_id,$part_body_html_personalized_id);
$email_message->ReplacePart($part_body_text_id,$part_body_text_personalized_id);


Once more: thanks!

Horst