graham23s Posted August 23, 2008 Share Posted August 23, 2008 Hi Guys, i'm at stale mate with my mass-emailing form! the way i have coded it so far there is a drop down box with: MASS E-MAIL ALL CUSTOMERS email1 email2 email3 you can select the top one which emails everyone or select individual emails <?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 $emails_array = array($emails); print_r($emails_array); } else { // Single email $to = "$c_e"; $subject = "$c_s"; $from = "info@firstchoicepharmacy.co.uk"; $body = "<h3>Newsletter from firstchoicepharmacy.co.uk</h3>"; $body .= "<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 />"); } } } // End main isset break; ?> emailing singly works great but im not sure how to go about doing the mass emailing part? any help would be great thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/121002-mass-emailing/ Share on other sites More sharing options...
BlueSkyIS Posted August 23, 2008 Share Posted August 23, 2008 loop over the selected email addresses, mail()'ing to each one. Quote Link to comment https://forums.phpfreaks.com/topic/121002-mass-emailing/#findComment-623768 Share on other sites More sharing options...
coder500 Posted August 23, 2008 Share Posted August 23, 2008 According to PHP manual, The mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient. For the sending of large amounts of email, see the » PEAR::Mail, and PEAR::Mail_Queue packages. Quote Link to comment https://forums.phpfreaks.com/topic/121002-mass-emailing/#findComment-623779 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Share Posted August 23, 2008 I would advise PHP mailer. Quote Link to comment https://forums.phpfreaks.com/topic/121002-mass-emailing/#findComment-623797 Share on other sites More sharing options...
waynew Posted August 23, 2008 Share Posted August 23, 2008 I would advise not spamming people. Quote Link to comment https://forums.phpfreaks.com/topic/121002-mass-emailing/#findComment-623827 Share on other sites More sharing options...
corbin Posted August 23, 2008 Share Posted August 23, 2008 To build onto waynewex's post, I see what you're doing as spam too. In the US (if I remember correctly) and possibly other countries too, any periodic email that is based off of a mailing list must have an "unsubscribe" option. Now to be constructive: I've used PHPMailer for a couple hundred emails before, and it worked perfectly for me. Haven't used it with more than that though. Quote Link to comment https://forums.phpfreaks.com/topic/121002-mass-emailing/#findComment-623842 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.