eskander wrote in php 😤working

smtp problems with php

i feel like i'm either spamming the community or taking it over with my questions...

at any rate, i'm having some problems with my newsletter app again. the mail server issue is resolved, as far as i know. i haven't gtten any complaints from the admin about it so looks good for now.


my new problem is that when i'm sending a newsletter to our 5000+ subscribers it works until about 3800 and then i sporadically get these messages

Warning: mail() [function.mail]: Failed to connect to mailserver at "mta6.xxx.xxxx" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\Domains\pubvoyages.com\wwwroot\admin_portail\sends\pubvoyages\send\send_email.php on line 72
Could not send to 4141. xxx@xxx.ca

and this might happen to 5 emails consecutively but then i'll get to or three successful messages.
the port is set to 25 by default in php.ini so my though is, maybe i'm overloading the smtp server?

i overload the server and it closes port 25? is that possible? the server itself is a win2k3 box but i don't know what the mail server is. i'm not too familiar with win2k3 so i don't even know if it's possible to close port 25 if it's under a perceived threat.


doing a little research i found a site that logs into the smtp. didn't think this was necessary considering that it's sending to ~4000 email addresses without me logging in.

here's the gist of the code

for($i=0;$i<sizeof($emails);$i++)
{
if($i == 0)
{
ob_start();
}
if (mail($emails[$i], $subject, $letter, $headers))
{

print "<div align='left'>".($i+1).". Sent to ".$emails[$i]."</div>";
if($i % 20 == 0 && $i > 10)
{
print "Sent to $i email addresses.";
ob_end_flush();
ob_start();
}
if($i == 3400)
{
sleep(4);
}
}
else
{
print "<div style='font-weight:bold;' align='left'>Could not send to $i. ".$emails[$i]."</div><br />";
}

}

ob_flush doesn't seem to want to work whatsoever, and the last thing i added was the 3400 then sleep for 4 secs thinking that i'd give the smtp a break. maybe it's just not long enough.


any help would be greatly appreciated.
Thanks


edit
sorry bout stretching the layout


EDIT X2
i somewhat solved the issue.
basically i'm sending the emails through bcc now and the script doesn't timeout and it sends to everyone as far as i can tell. i still can't flush yet and there's no real way to check if the email actually goes out aside from checking how many people have viewed the email.


not the ideal solution but it is the way that the old programmer did it as well.


thanks everyone for your help, i still want to try closing and starting a new smtp session for every email that needs to go out.