PHP Mail question!

Hi!

Im running a mail script on my server but when i shall send emails to all my users like 3000 i can only send like 200 emails then it returns with a error.
Exactly the same as this example:

I am working on a job board for a client and i am trying to do a mass email to all jobseekers(there are currently over 1000 jobseekers). When i try to send out emails to just some of the jobseekers, it works fine. But when i try to send out emails to all the jobseekers, i am getting the following error:
Warning: mail() [function.mail]: could not execute mail delivery program '/usr/sbin/sendmail -t -i' in /home/ployjam/public_html/admin/emailall.php on line 63

Warning: mail() [function.mail]: could not execute mail delivery program ‘/usr/sbin/sendmail -t -i’ in /home/ployjam/public_html/admin/emailall.php on line 63

Warning: mail() [function.mail]: could not execute mail delivery program ‘/usr/sbin/sendmail -t -i’ in /home/ployjam/public_html/admin/emailall.php on line 63

Warning: mail() [function.mail]: could not execute mail delivery program ‘/usr/sbin/sendmail -t -i’ in /home/ployjam/public_html/admin/emailall.php on line 63

Warning: mail() [function.mail]: could not execute mail delivery program ‘/usr/sbin/sendmail -t -i’ in /home/ployjam/public_html/admin/emailall.php on line 63

Warning: mail() [function.mail]: could not execute mail delivery program ‘/usr/sbin/sendmail -t -i’ in /home/ployjam/public_html/admin/emailall.php on line 63

Warning: mail() [function.mail]: could not execute mail delivery program ‘/usr/sbin/sendmail -t -i’ in /home/ployjam/public_html/admin/emailall.php on line 63


Anyway when i contacted my server admin of the VPS he replied:
Thank you. Yes, I understand the issue. I also had a word with our system administrators and the reason for this has been found. The maximum simultaneously running user processes allowed by the system per VPS node are as follows:

regular 480

This is a restriction we would not change from a security and performance point of view.

You can either:

  • re-write your script to send the messages in pack of 150 for instance.
  • find a ready-to-use script to do so.

Well so now my question is. Does anyone knows how to rewrite this email function so it can send the mails in a loop, i mean send like 50 email at one time and then send another 50 emails?

Heres the script (emailtousers.php):

<?php
require_once("functions.php");
require_once("config.php");

$readyto=(isset($_POST["readyto"])?$_POST["readyto"]:"sa");
$readyto1=(isset($_POST["readyto1"])?$_POST["readyto1"]:"sa");
$kullan=(isset($_POST["kullan"])?$_POST["kullan"]:3);
$konu=(isset($_POST["konu"])?$_POST["konu"]:"Subject!");
$mailbolumu=(isset($_POST["mailbolumu"])?$_POST["mailbolumu"]:"Mail Body!");

$count=0;
block_begin("Email to Users");
?>
<center>
<TABLE width=20% class="lista">
<TR>
<TD align="center" class="header"><? echo "E-Mail to Users"; ?></TD></TR>
<TR><TD align="center" class="blocklist">
<?php
print("<form method=post action=admincp.php?user=".$CURUSER["uid"]."&code=".$CURUSER["random"]."&do=emailtousers>");
?>
<!-- <form method=post action="admincp.php?user=<?php echo $CURUSER["uid"]; ?>&code=<?php echo $CURUSER["random"]; ?>&do=emailtousers"> -->
<!-- <form method=post action="admincp.php?user=".$CURUSER["uid"]."&code=".$CURUSER["random"]."&do=emailtousers"> -->
</TD></TR>
<tr>
<td>
<b>Subject </b><input name="konu" type="text" id="konu" size="60" maxlength="60" />
</td>
</tr>
<tr>
<td>
<b>Mail</b><br />
<textarea name="mailbolumu" cols="57" rows="5" id="mailbolumu"></textarea>
</td>
</tr>
<tr>
<td align="center" class="blocklist">
User Group : <!Dropdown added by miskotes>

         <?
         print("<select name="kullan">");
         print("<option value=0".($level==0 ? " selected=selected " : "").">".ALL."</option>");
         $res=mysql_query("SELECT id,level FROM users_level WHERE id_level>1 ORDER BY id_level");
         while($row=mysql_fetch_array($res))
         {
             $select="<option value='".$row["id"]."'";
             if ($level==$row["id"])
                $select.="selected="selected"";
             $select.=">".$row["level"]."</option>n";
             print $select;
         }
         print("</select>");
         ?>

<!End dropdown>

</td>
</tr>
<TR><TD align="center" class="lista">
<input type="submit" name="readyto" value="Send Email"><input name="readyto1" type="submit" id="readyto1" value="Send Activation Mail"></td></tr></form></table><br>
</center>
<?php
if ($readyto=="Send Email") {
?>
<TABLE width=100% class=lista cellpadding=0 cellspacing=0>
<TR><TD align="center" height="20px" class="block"><b>Emailed Users USER GROUP : <? echo ($kullan==0?"ALL":$kullan) ?></b></TD></TR></table>
<center>
<?php
if ($kullan==0) {
$q=mysql_query("SELECT users.id as id, username, random, email, language, downloaded, uploaded, level, UNIX_TIMESTAMP(joined) as joined, UNIX_TIMESTAMP(lastconnect) as lastconnect FROM users LEFT JOIN users_level ON users.id_level=users_level.id ORDER BY (uploaded / downloaded) ASC");
}
else
{
$q=mysql_query("SELECT users.id as id, username, random, email, language, downloaded, uploaded, level, UNIX_TIMESTAMP(joined) as joined, UNIX_TIMESTAMP(lastconnect) as lastconnect FROM users LEFT JOIN users_level ON users.id_level=users_level.id where (users.id_level='".$kullan."') ORDER BY (uploaded / downloaded) ASC");
}
while ($user=mysql_fetch_object($q)) {
if ($user) {
echo "<b>".$user->username."</b> emailed!<br>";
mail($user->email,$konu,$mailbolumu,"From: PantheraBits <[email protected]>");
   $count++;
}
}

echo "<br><br> Found <b>".$count."</b> users and emailed!</b>";

}
if ($readyto1=="Send Activation Mail") {
if ($kullan==0) {
$q=mysql_query("SELECT users.id as id, username, random, email, language, downloaded, uploaded, level, UNIX_TIMESTAMP(joined) as joined, UNIX_TIMESTAMP(lastconnect) as lastconnect FROM users LEFT JOIN users_level ON users.id_level=users_level.id ORDER BY (uploaded / downloaded) ASC");
}
else
{
$q=mysql_query("SELECT users.id as id, username, random, email, language, downloaded, uploaded, level, UNIX_TIMESTAMP(joined) as joined, UNIX_TIMESTAMP(lastconnect) as lastconnect FROM users LEFT JOIN users_level ON users.id_level=users_level.id where (users.id_level='".$kullan."') ORDER BY (uploaded / downloaded) ASC");
}
while ($user=mysql_fetch_object($q)) {
if ($user) {
//echo "www.pantherabits.com/account.php?act=confirm&confirm=".$user->random."&language=".$user->language." <br>";
echo "<b>".$user->username."</b> emailed!<br>";
mail($user->email,"activation subject","Activation link       http://www.yoursite.com/account.php?act=confirm&confirm=".$user->random."&language=".$user->language,"From: pantherabits <[email protected]>");
   $count++;
}
}
echo "<br><br> Found <b>".$count."</b> users and emailed!</b>";

}
   block_end();

?>

I would be very glad if anyone could help me with this one :)
Thanks in advice and sorry 4 my bad gramma.

Cheers

Presumably your users emails are in a database…

Adjust the query by adding a limit. start at LIMIT 0, 199.

Then you can add a “RE-DIRECT” to a page with an id in the URL (perhaps the same page) such as
http://example.com/mail.php?start=200
then use the $_GET[‘start’] to adjust the next query so the limit would be LIMIT 200, 399
and so on…

Because it will take time to send the email… maybe use a “Meta Redirect” with a delay of 30 seconds.

It will take longer to do but it may be a good work around.

Sponsor our Newsletter | Privacy Policy | Terms of Service