liderbug Posted June 9, 2013 Share Posted June 9, 2013 My code - perloined from some site some time back as howto Pear Mail.php example. ---------------------------------------------------------------- $host = "relay.dnsexit.com"; $username = "myname"; $password = "mypass"; # $to = "$em[0]"; #em = result mysql_query select... $to = "me@myemail.com $mime = new Mail_mime(array('eol' => $crlf)); $mime->setTXTBody($text); $mime->setHTMLBody($html); $headers = array ( 'from' => "Editor@ournewspaper.com", 'to' => $to, 'reply-to' => "Editor@ournewspaper.com", 'subject' => "Your weekly News"); $headers = $mime->headers($headers); $smtp = Mail::factory('smtp', array ( 'host' => $host, 'username' => $username, 'password' => $password, 'auth' => true, 'port' => 80 # port 25 gives the same results )); $body = $mime->get(); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)... ------------------------------------------------------------------- If I run the program in a loop of 5 emails (although all come to me) I get: Failed to connect to relay.dnsexit.com:80 [sMTP: Failed to connect socket: Connection refused (code: -1, response: )] OK OK Failed... OK It's doing the exact same thing 5 times in a row but fails at random. The next time all 5 fail, the next time the first one fails followed by 4 OK's. I can loop "$fp = fsockopen("relay.dnsexit.com", 25, $errno, $errstr, 30);" 20 times and no failures. Any thoughts? Thanks Chuck Quote Link to comment https://forums.phpfreaks.com/topic/278953-pear-mailphp-fails-randomly/ Share on other sites More sharing options...
kicken Posted June 9, 2013 Share Posted June 9, 2013 There is always the potential for a network connection to fail. Temporary outages, firewalls, etc. You just need to check for such errors and handle them in some way such as re-trying, logging the problem, indicating failure to the end-user, etc. Quote Link to comment https://forums.phpfreaks.com/topic/278953-pear-mailphp-fails-randomly/#findComment-1434945 Share on other sites More sharing options...
liderbug Posted June 9, 2013 Author Share Posted June 9, 2013 Stumbled across the problem : $host = "relay.dnsexit.com"; Seems that name can return 2 different IP addresses 64.182.102.185/186 I hard coded 185 and sent 5 for 5, 5 for 5, 5 for 5. Just checked 186 went 0 for 5. So, Kicken, you were/are real close. My final comment.... @@#^! %*&^ @* computers!!! Quote Link to comment https://forums.phpfreaks.com/topic/278953-pear-mailphp-fails-randomly/#findComment-1434947 Share on other sites More sharing options...
liderbug Posted June 9, 2013 Author Share Posted June 9, 2013 Woke up today and mind still mulling - Pear Mail will randonly fail because one of two IP's associated with one URL doesn't respond. But fsockopen("relay.dnsexit.com" worked every time. Hmmmm, must assume the two processes do getaddressinfo (or whatever) differently. OK, I think I can (gawd I hope...) I can drop the subject :-/ Quote Link to comment https://forums.phpfreaks.com/topic/278953-pear-mailphp-fails-randomly/#findComment-1434989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.