From e3314c44ed569d09e5d3653419550f3a02d8a4be Mon Sep 17 00:00:00 2001 From: Synchro Date: Thu, 24 Apr 2014 14:39:33 +0200 Subject: [PATCH] Fix body setting in list example --- examples/mailing_list.phps | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/mailing_list.phps b/examples/mailing_list.phps index b130a927..070e82d3 100644 --- a/examples/mailing_list.phps +++ b/examples/mailing_list.phps @@ -22,15 +22,20 @@ $mail->addReplyTo('list@example.com', 'List manager'); $mail->Subject = "PHPMailer Simple database mailing list test"; -//connect to the database and select the recipients from your mailing list that have not yet been sent to +//Same body for all messages, so set this before the sending loop +//If you generate a different body for each recipient (e.g. you're using a templating system), +//set it inside the loop +$mail->msgHTML($body); +//msgHTML also sets AltBody, so if you want a custom one, set it afterwards +$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; + +//Connect to the database and select the recipients from your mailing list that have not yet been sent to //You'll need to alter this to match your database $mysql = mysql_connect('localhost', 'username', 'password'); mysql_select_db('mydb', $mysql); $result = mysql_query("SELECT full_name, email, photo FROM mailinglist WHERE sent = false", $mysql); while ($row = mysql_fetch_array($result)) { - $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; - $mail->msgHTML($body); $mail->addAddress($row['email'], $row['full_name']); $mail->addStringAttachment($row['photo'], 'YourPhoto.jpg'); //Assumes the image data is stored in the DB