Jump to content

Pear Mail.php fails randomly


liderbug

Recommended Posts

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 = "[email protected]

                        $mime = new Mail_mime(array('eol' => $crlf));
                        $mime->setTXTBody($text);
                        $mime->setHTMLBody($html);
                        $headers = array (
                                'from' => "[email protected]",
                                'to' => $to,
                                'reply-to' => "[email protected]",
                                '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

 

 

Link to comment
https://forums.phpfreaks.com/topic/278953-pear-mailphp-fails-randomly/
Share on other sites

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.

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!!!

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 :-/

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.