graham23s Posted July 26, 2008 Share Posted July 26, 2008 Hi Guys, im trying to figure out the best way to do the mass email part of my code, i have put a while loop in but not sure if thats best: <?php case "mass-email": // How many emails $q_num = "SELECT * FROM `fcp_customers`"; $r_num = mysql_query($q_num); $n_num = mysql_num_rows($r_num); print("<form action=\"admin.php?page=mass-email\" method=\"POST\">"); // Mass e-mails form print("<table width='80%' border='0' cellpadding='5' cellspacing='1' />\n"); print("<tr>\n"); print("<th colspan='2'>Mass E-Mail Customers</th>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class='td_style' align='left' valign='top'>E-Mail:</td><td class='td_style' align='left'><select name=\"cus_emails\"><option value=\"email_all\">--> MASS EMAIL ALL CUSTOMERS! - ($n_num) <--</option>"); $q_emails = "SELECT * FROM `fcp_customers`"; $r_emails = mysql_query($q_emails); // Loop while ($a_emails = mysql_fetch_array($r_emails)) { // Customers email $emails = $a_emails['email']; // Print print("<option value=\"$emails\">$emails</option>"); } print("</select></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" align='left' valign=\"top\">E-Mail Subject:</td><td class='td_style' align='left'><input type=\"text\" name=\"cus_subject\" size=\"70\"></td>"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" align='left' valign=\"top\">E-Mail Message:</td><td class='td_style' align='left'><textarea name=\"cus_message\" rows=\"20\" cols=\"70\"></textarea></td>"); print("</tr>\n"); print("<tr>\n"); print("<td colspan='2' class='td_style' align='right'><input type='submit' name='submit_emails' class=\"btn_style\" value='Send!'></td>\n"); print("</tr>\n"); print("</table>"); print("</form>"); // Deal with the submission if (isset($_POST['submit_emails'])) { // Post vars $c_e = $_POST['cus_emails']; $c_s = $_POST['cus_subject']; $c_m = $_POST['cus_message']; // Mass or single email if ($c_e == 'email_all') { // Mass email while () { } } else { // Single email $to = $c_e; $subject = $c_s; $from = "[email protected]"; $body = "<h3>Newsletter from firstchoicepharmacy.co.uk</h3>"; $body .="<br /><br />"; $body .="$c_m<br /><br />"; $body .="Regards <br /><a href=\"http://www.firstchoicepharmacy.co.uk\">http://www.firstchoicepharmacy.co.uk</a>"; $headers = "MIME-Version: 1.0\r\n"; $headers = "From: firstchoicepharmacy.co.uk<$from>\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $mail = mail($to,$subject,$body,$headers); // Success if ($mail) { print("<br /><span class=\"mail_ok\"><img src=\"images/tick.png\"> You have successfully emailed [<b>$to</b>]</span><br /><br /><br />"); } } } break; ?> not sure what to do with the while loop exactly lol any help would be great Graham Link to comment https://forums.phpfreaks.com/topic/116782-mass-emailing/ Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 you put the emails into an array , and do a foreach loop Link to comment https://forums.phpfreaks.com/topic/116782-mass-emailing/#findComment-600538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.