NETSYNC Posted June 10, 2011 Share Posted June 10, 2011 Hey all I have this code: $ret = mysql_query($q); $emails = array(); while ($row = mysql_fetch_assoc($ret)) { $emails[] = $row['num'].'@messaging.sprintpcs.com'; } if ($emails) { $ToEmail = implode(', ', $emails); $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = ($_POST["message"]); // $MESSAGE_BODY .= ($_POST["auth"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); } This has worked great for a custom script that emails users the content of a form. The issue is with the number of emails. It can get up to 200 or so and when it does the emails never come. We are assuming its hitting something on the server end or after it leaves. My next idea is to break this script up so it does it in batches instead of how it is now. Where would I start on this to do the exact same thing, but do it in batches of 50 if its more than that? Thanks for any insight and help. Quote Link to comment https://forums.phpfreaks.com/topic/238979-changing-an-email-script-to-do-batches-instead/ Share on other sites More sharing options...
NETSYNC Posted June 10, 2011 Author Share Posted June 10, 2011 Here is what I am trying but it is giving me an implode error. <?php if(!empty($_POST["recip"])){ switch ($_POST["recip"]) { case 'sl': $q = "select `num` from `sprint` WHERE dept ='T_SUP' OR `dept` ='T_LEAD' OR `dept` ='M_LEAD' OR `dept` ='T_MGR' OR `dept` ='T_VP' OR `dept` ='M_MGR'"; break; case 'mgt': $q = "select `num` from `sprint` WHERE dept ='T_SUP' OR `dept` ='S_SUP' OR `dept` ='O_MG' OR `dept` ='T_MGR' OR `dept` ='S_VP' OR `dept` ='Q_SUP' OR `dept` ='S_MGR' OR `dept` ='T_VP' OR `dept` ='M_MGR'"; break; case 'sunday': $q = "select `num` from `sprint` WHERE id ='7708' OR `id` ='7743' OR `id` ='7426' OR `id` ='7479' OR `id` ='7203' OR `id` ='7231' OR `id` ='7271' OR `id` ='7221'"; break; case 'sil': $q = "select `num` from sprint WHERE `sup` ='Silvio'"; } if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } $ret = mysql_query($q); $emails = array(); while ($row = mysql_fetch_assoc($ret)) { $emails[] = $row['num'].'@messaging.sprintpcs.com'; } array_chunk($emails, 50); if ($emails) { foreach($emails as $mail) { $ToEmail = implode(', ', $mail); $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = ($_POST["message"]); // $MESSAGE_BODY .= ($_POST["auth"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); } } $num_rows = mysql_num_rows($ret); ?> Quote Link to comment https://forums.phpfreaks.com/topic/238979-changing-an-email-script-to-do-batches-instead/#findComment-1227966 Share on other sites More sharing options...
NETSYNC Posted June 11, 2011 Author Share Posted June 11, 2011 Any help on why this would cause an implode error? Did I separate them wrong? Quote Link to comment https://forums.phpfreaks.com/topic/238979-changing-an-email-script-to-do-batches-instead/#findComment-1228281 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.