Meena
Meena

Reputation: 967

Unable to send mail to more than 200 member at at a time using php mail function

Hello guy i am using php mail function to deliver my mails if i run the code locally with 5 email id then it working fine without any error but if i run the same code with more than 400 email id then it show the warning messages link

Warning: mail() [function.mail]: Could not execute mail delivery program '/usr/sbin/sendmail -t -i' in /home/sendInvite.php on line 147 

i am using this code :

$sqlquery1 = "select employee from empl where sstatus != 'C'";
 $sqlmath1 = mysql_query($sqlquery1) or die("Error: (" . mysql_errno() . ") " . mysql_error());
     $cnt = mysql_num_rows($sqlmath1);
     if($cnt !="0") {
     while($query1 = mysql_fetch_array($sqlmath1))
     {
    $email1=$query1['employee'];  
    $emid1=base64_encode($email1);
    $sid1 =base64_encode($sidtest);
    $email_from1 = "[email protected]";
     $link1="http://www.xx.php?mid=$emid1&sid=$sid1";
    //send mail
    $emailto_web1     = $email1;
    $email_headers1   = "From: ".$email_from1;
    num_sent_web1    = 0;
    $email_message21  = "Dear Employee, \n";
    $email_message21 .= "\n";
    $email_message21 .= "If you cannot click on the URL, copy the URL and paste it on your address bar.\n";
    $email_message21 .= "\n";
    $email_message21 .= $link1."\n";
    $email_message21 .= "\n\n\n";
    $email_message21 .= "Regards,\n";
    $email_message21 .= "Admin Team. \n";

    $mail_web1 = mail($emailto_web1,$email_subject1,$email_message21,$email_headers1);
    if($mail_web1)
        {    $err = "Remainder Send Successfully";
                }
                else 
                    {  $err=$email." Try Again";
                        } 
      }  
      } // not equal to zero condition

I dont know the exact reason why i receive this warning message, Please Post your valuble suggestion. Thanks in advance !!!

Upvotes: 0

Views: 635

Answers (4)

ryryan
ryryan

Reputation: 3928

Your best option is to use a cron job. Doing it like this, your server will have a lot of stress. The mail() function isn't meant for a large volume of emails. It will slow done your server if your using a large amount.

This will explain how to make a cron job on your server.

Hope it helps!

Upvotes: 0

Aqeel Ahmad
Aqeel Ahmad

Reputation: 473

I think there is no problem with your script but its rather an installation issue with your operating system or sending mail program is poorly configured or perhaps missing. Try all possibilities, from php side its okay.

Upvotes: 0

user319198
user319198

Reputation:

Please see the php mail function documentation:

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient. For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Also, see the related questions on serverfault: https://serverfault.com/questions/67154/sending-an-email-to-about-10k-users-not-spam, where PHPlist is mentioned, along with others. And here - https://serverfault.com/questions/68357/whats-the-best-way-to-send-bulk-email,https://stackoverflow.com/questions/1543153/is-there-a-limit-when-using-php-mail-function

Upvotes: 0

Adeel
Adeel

Reputation: 615

Use cron job for this and send mails in chunks instead of sending all mails in one time.

Upvotes: 3

Related Questions