$to_name = $to[$recipient]["name"]; $email_message->SetEncodedEmailHeader("To", $to_address, $to_name); /* Do we really need to personalize the message body? * If not, let the class reuse the message body defined for the first recipient above. */ if (!$email_message->cache_body) { /* * Create a personalized body parts, either HTML and text * alternative parts. */ $first_name = strtok($to_name, " "); $balance = number_format($to[$recipient]["balance"], 2); $html_smarty->assign("firstname", HtmlEntities($first_name)); $html_smarty->assign("balance", HtmlEntities($balance)); $html_smarty->assign("email", HtmlEntities($to_address)); $email_message->CreateQuotedPrintableHtmlPart($html_smarty->fetch("mailing.html.tpl"), "", $recipient_html_part); /* Make the personalized replace the initially empty HTML part */ $email_message->ReplacePart($html_part, $recipient_html_part); $text_smarty->assign("firstname", $first_name); $text_smarty->assign("balance", $balance); $text_smarty->assign("email", $to_address); $email_message->CreateQuotedPrintableTextPart($email_message->WrapText($text_smarty->fetch("mailing.txt.tpl")), "", $recipient_text_part); /* Make the personalized replace the initially empty text part */ $email_message->ReplacePart($text_part, $recipient_text_part); } /* Send the message checking for eventually acumulated errors */ $error = $email_message->Send(); if (strlen($error)) { break; } }