Jump to content

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 = "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

 

 

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.