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. Also, I am much better with HTML so this coding is greek to me.
Here is the newsletter script:
PHP Code:
<?
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 "<br><br><center>There are no registered members, yet!</center>";
exit();
}
?>
<script>
function CheckMail() {
if(document.f1.sub.value=="")
{
alert('Enter the newsletter subject line, please!');
document.f1.sub.focus();
return false;
}
if(document.f1.MyMessage.value=="")
{
alert('Enter the newsletter text, please!');
document.f1.MyMessage.focus();
return false;
}
}
</script>
<br><br>
<form method=post onsubmit="return CheckMail();" name=f1>
<table align=center width=500>
<tr>
<td></td>
<td><b>Newsletter</b><br><?=$error?></td>
</tr>
<tr>
<td align=right>Subject:</td>
<td><input type=text name=sub size=36></td>
</tr>
<tr>
<td align=right valign=top>Message:</td>
<td><textarea name=MyMessage rows=10 cols=35></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type=submit name=s1 value="Send" class="sub1"></td>
</tr>
</table>
</form>
<?
require_once("admin_footer.php");
?>
Re: PHP Script Limit Emails Being Sent??
In your while() loop, your only condition is so long as there is a new line in the SQL query results. Add an integer variable inside the loop which starts at 0 and increments by 1 (ie. $i++;). Then inside the conditional clause of the while() you can add an "or $i == x" (ie. || $i == 200;).