$addresses = count($linkarray[1]); echo "<br>There are ".$addresses." addresses to email"; $prefixno = count($prefixes); $c = 0; $n = 0; $y = 0; WHILE ($y < sizeof($prefixes)+1){ $shortened = preg_replace('/^"http:\/\/(www\.)?([^\/]+).*"$/i', '$2', $linkarray[1][$n]); //ECHO "<br>$prefixes[$y]@$shortened"; //mail("$prefixes[$y]@$shortened", "$subject", "$message", "From: $from"); mail("bean_beans2001@yahoo.co.uk", "$subject", "$message", "From: $from"); ob_get_contents(); ob_flush(); flush(); $c++; IF ($y == sizeof($prefixes)){ $n++; ECHO "<br>Sent request to: $prefixes[$y]@$shortened ..."; $y = 0; //Sleep(1); }else{ IF ($c == ($addresses*$prefixno)){ echo "<br><br>REQUESTS COMPLETE"; exit; }ELSE{ $y++; } } } PHP: This sends a lot of Emails, around 135. It takes A VERY long time send the emails and to give any output (why I put flushes there, to tell whether it's doing something). Could anyone explain why it's taking so long and/or how to make it a lot quicker? All help appreciated, Thanks, Lee.
I don't specifically see anything that should cause it to be extremely slow. Have you tried echoing some test statements after each function (mail, ob's, flush) to see if one of those is causing the delay? Is server load high? How come the result from ob_get_contents(); isn't being assigned to anything?
When I substitute the array that puts all the email prefixes and domains together with my email address, it emails and gives output much, much more quicker. So, I'm guessing gathering the email addresses from the search result and using a loop to attach 15 prefixes to each of the 9 domains, is the time drainer. Maybe If I assign all the prefixes to the domains before hand, into a new single array, which could then be mail()'d, would be quicker? Thanks, Lee.
Yeah. From what I can gather from your code, you're running 'mail' for every receipient, right? I'd consider the note at http://php.net/manual/en/function.mail.php : Note: 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.