$email_message->AddPart($text_part); /* Iterate personalization for each recipient. */ for ($recipient = 0; $recipient < count($to); $recipient++) { /* Personalize the recipient address. */ $to_address = $to[$recipient]["address"]; $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 part. */ $message = "Hello " . strtok($to_name, " ") . ",\n\nThis message is just to let you know that Manuel Lemos' e-mail sending class is working as expected for sending personalized messages.\n\nThank you,\n{$from_name}"; $email_message->CreateQuotedPrintableTextPart($email_message->WrapText($message), "", $recipient_text_part); /* Make the personalized replace the initially empty 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; } } /* When you are done with bulk mailing call the SetBulkMail function * again passing 0 to tell the all deliveries were done. */ $email_message->SetBulkMail(0); if (strlen($error)) { echo "Error: {$error}\n"; } echo "Done!\n";