PHP Script Limit Emails Being Sent??

Hi Everyone,

I am new to this site and hope I am posting in the right area. I have a website and I need help with some coding. I need to limit the amount of newsletters that are sent out to my registered users.

Can someone tell me how to add a line or so in this script to maybe choose sending to members 1 - 200 and then I could change to at any time to send it to different member numbers?

I really appreciate any information that is given. Thank you so much for your time.

Here is the newsletter script:

<? require_once("../conn.php"); require_once("access.php"); require_once("AdminNavigation.php"); if(isset($_POST[s1])) { $q1 = "select * from class_members"; $r1 = mysql_query($q1) or die(mysql_error()); while($a1 = mysql_fetch_array($r1)) { $to = $a1[email]; $subject = $_POST[sub]; $message = $_POST[MyMessage]; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; $headers .= "Content-Transfer-Encoding: 8bit\n"; $headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n"; $headers .= "X-Priority: 1\n"; $headers .= "X-MSMail-Priority: High\n"; $headers .= "X-Mailer: PHP/" . phpversion()."\n"; mail($to, $subject, $message, $headers); $i++; } $error = "$i messages was sent"; } //get the number of registered members $q1 = "select count(*) from class_members"; $r1 = mysql_query($q1) or die(mysql_error()); $a1 = mysql_fetch_array($r1); if($a1[0] == 0) { echo "

There are no registered members, yet!"; exit(); } ?>



Newsletter
<?=$error?>
Subject:
Message:
&nbsp
<? require_once("admin_footer.php"); ?>

Modify your select query with a where clause with user ID between this number and that number.

WHERE user_id BETWEEN 1 AND 200

Also, you are using deprecated code. You need to use PDO or mysqli with prepared statements.

WHERE user_id BETWEEN 1 AND 200

Is that exactly how I type it in? Where should I put it in the programming?

Thanks so much for your help!!

[member=72905]wendy531[/member], [member=46186]Kevin Rubio[/member] is assuming you have a user_id in your class_members table…

[php]$q1 = “select * from class_members where user_id between 100 and 200”;
[/php]

But, it might be called something else in your database, also we have no clue how the data in your table is represented to give the exact sql statement, you didn’t share that information with us.

But, if you do something like this, it will select the first 200 members in the table.

[php]SELECT * FROM class_members LIMIT 200[/php]

It is actually MemberID. So it should read:

[php]$q1 = “select * from class_members where MemberID between 100 and 200”;[/php]

Correct?

Sound like you wanted between 1 and 200 not 100 and 200. and yes the sql is correct.

Also if your memberid is not sequential and if it doesn’t start with 1 you might end up getting less then 200 members.

Sponsor our Newsletter | Privacy Policy | Terms of Service