sending around 5000mails at a time using mail() function php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yerupalleyskumar
Forum Newbie
Posts: 8
Joined: Wed Mar 17, 2004 11:04 pm
Location: Tokyo
Contact:

sending around 5000mails at a time using mail() function php

Post 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
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Is it sending to only 1000?
yerupalleyskumar
Forum Newbie
Posts: 8
Joined: Wed Mar 17, 2004 11:04 pm
Location: Tokyo
Contact:

no

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
yerupalleyskumar
Forum Newbie
Posts: 8
Joined: Wed Mar 17, 2004 11:04 pm
Location: Tokyo
Contact:

how do i do that

Post by yerupalleyskumar »

hai ,i am new to PHP
how do i do that ???sample of code will be very helpful..............
thanq
suresh :cry:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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...
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You may find the phpmailer-class handy for that.
Post Reply