Jump to content

Changing an email script to do batches instead?


NETSYNC

Recommended Posts

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.

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);





?>


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.