Page 1 of 1
sending around 5000mails at a time using mail() function php
Posted: Wed Mar 17, 2004 11:04 pm
by yerupalleyskumar
hai
i am new to PHP,i ahve a problem with sending mails from PHP using function mail()......actually it is not sending mails to all 5000 users..
here is my code
$x = 1;
$hold = 1000;
foreach($emails as $meru)
{
if($meru!=""){
if(send_japanese_mail($meru,$sub,$body,$from,$from_email,$bcc))
{
print "<img src=\"/img/hprog_02.gif\">";
flush();
}
if($x == $hold)
{ // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
sleep(3); //value must always be 3
$x=0;
}
$x++;
}//end of if mail address is not empty
}//end of foreach $mer
thanq in advance
Posted: Wed Mar 17, 2004 11:20 pm
by Steveo31
Is it sending to only 1000?
no
Posted: Thu Mar 18, 2004 12:56 am
by yerupalleyskumar
thanq for ur reply
Actually it is sending to all email ids but its taking a lot of memory space in linux server and wasting system resourses,so is there any better way of sending mails.......
guide me
bye
Posted: Thu Mar 18, 2004 1:36 am
by m3mn0n
Yes.
Method #1: Increase the PHP resource limits, and increase the max script execution time.
Method #2: Why do all at the same time? Split up the job into 5 or 10 different mailings.
Hope this helps.
how do i do that
Posted: Thu Mar 18, 2004 1:44 am
by yerupalleyskumar
hai ,i am new to PHP
how do i do that ???sample of code will be very helpful..............
thanq
suresh

Posted: Thu Mar 18, 2004 2:58 am
by JayBird
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... not very efficient.
To send email using sockets, I suggest reading this:
http://cr.yp.to/smtp.html
I would not recommend using the mail() function in PHP for anything over 100 mails, not even using it by breaking out your recipients in batches of 25, 50, 100 etc. and looping with the function.
The mail function in general is pretty weak - your best option would be to open a socket to SMTP and package up the mail in an env and send it at once by using 'RCPT TO:' in the SMTP connection.
Make your connection by using fsockopen() or popen().
Look through the user notes on fsockopen() and you will see a few examples of sending mail to SMTP using this...
Mark
Posted: Thu Mar 18, 2004 4:56 am
by m3mn0n
Bech100 wrote:This function opens and closes an SMTP socket for each email... not very efficient.
Indeed. I wish they would build in an alternative method for sending e-mail that used sockets the way some mail-socket modules work.
If only...
Posted: Thu Mar 18, 2004 6:15 am
by patrikG
You may find the
phpmailer-class handy for that.