Link to home
Start Free TrialLog in
Avatar of bdichiara
bdichiaraFlag for United States of America

asked on

Retreiving Email headers with PHP

I have seen several places on php.net and other sites that claim to be able to access emails via PHP, and some places that say access emails in your Gmail/gmail for your domain account. I am having trouble doing this. I have not been able to connect and retrieve the headers successfully. I'm pretty sure there are no issues with my PHP.INI file. I have IMAP enabled. I do not have SSL on my server. That may affect it.

What I would like to do is send an email to a special email account, and then use a CRON job to check that account on a periodic basis. That CRON job can then execute some sort of script based on the email. Is this possible?

I have attached some sample code. The common error I get is either a Timeout or Invalid remote specification.
$mail = "";
$mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "username", "password")
     or die(imap_last_error());
 
echo "<h1>Mailboxes</h1>\n";
$folders = imap_listmailbox($mbox, "{imap.gmail.com:993/imap/ssl}", "*");
 
if ($folders == false) {
    $mail .= "Call failed<br />\n";
} else {
    foreach ($folders as $val) {
        $mail .= $val . "<br />\n";
    }
}
 
echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);
 
if ($headers == false) {
    $mail .= "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        $mail .= $val . "<br />\n";
    }
}
 
imap_close($mbox);
 
echo $mail;

Open in new window

Avatar of steelseth12
steelseth12
Flag of Cyprus image

using your script exactly as it is only adding
ini_set('max_execution_time',3600); on the top. It worked great .. and it took around 2 minutes but on the other hand i had over 8000 emails in my account.

Do you have imap enabled in your gmail account ?
Avatar of bdichiara

ASKER

Yes, I think i found out that it's pretty much enabled by default. I checked both of my accounts to make sure it was enabled, and it was, and I don't ever remember enabling it. Maybe if POP is enabled, it will automatically enable IMAP. Anyway, thanks for the help.

Mine is still taking a long time? Is it trying to get ALL my email?? Do you know if there is a way to limit the # of headers it fetches?

I get:
Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in mail.php on line 4
Can't connect to gmail-imap.l.google.com,993: Connection timed out
Avatar of Steve Bink
>>> Is it trying to get ALL my email??

Very likely.  IMAP depends on a 'bookmark' from the client to determine which mail is new.  Without that bookmark, it normally assumes that mail has never been downloaded, and everything is new.  In your example, you're using imap_headers(), which grabs all mail by default.

Take a look at the link below.  There are many functions available for dealing with IMAP boxes in PHP, and I'm sure you'll find everything you need:

http://www.php.net/manual/en/ref.imap.php
To try to troubleshoot this, I removed the entire headers section, and I should just be retrieving the folders, however I still get the same error. It's saying that the timeout is occurring on line 3, which is imap_open() line.  Could there be something else wrong or not set correctly?
Go back to steelseth12's question:  

>>> Do you have imap enabled in your gmail account ?

If so, try hitting it from an established IMAP client, such as Thunderbird.
I setup my account in thunderbird and after following the instructions here:
http://mail.google.com/support/bin/answer.py?answer=77662

I was able to download all my folders and messages very quickly. What should I try next?
## IP address obfuscated
## modus_operandi

I copied your code into a new PHP file, changed the username and password, and saved it.  It worked the very first try.  The code is good...it must be something else preventing your connection to gmail's server.  Here's a couple ideas you can check:

1) On the server running the script, check your connectivity to imap.gmail.com.  Ping it a few hundred times to make sure it is consistent.
2) Check your phpinfo() output for the IMAP module.  You should see entries for SSL and Kerberos support.  At a minimum, you're going to need SSL.  I'm not sure about Kerberos.  Mine shows both enabled.
3) Check imap_errors() and imap_alerts() for any additional information in the IMAP error stack.
4) Review your PHP logs for any PHP-related errors not being printed to the result.

Finally, you can test the session manually if you have the openssl app.  I'm only familiar with how this works on nix.  I imagine it would be much the same on Windows.  Here's a copy of my attempt from a few moments ago:

#> openssl s_client -bugs -host imap.gmail.com -port 993 -quiet
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
verify error:num=27:certificate not trusted
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
verify error:num=21:unable to verify the first certificate
verify return:1
* OK Gimap ready for requests from <IP address> e76if392739hse
01 LOGIN myuser@gmail.com mypassword
01 OK myuser@gmail.com authenticated (Success)
## IP address obfuscated
## modus_operandi

My earlier test fails immediately after the LOGIN because openssl s_client does not send a return (crlf).  Here's a new copy of the same test, plus some:

#> openssl s_client -host imap.gmail.com -port 993 -crlf -quiet
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
verify error:num=27:certificate not trusted
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
verify error:num=21:unable to verify the first certificate
verify return:1
* OK Gimap ready for requests from <IP address> 30if399876hso
01 LOGIN myuser@gmail.com mypass
01 OK myuser@gmail.com authenticated (Success)
02 LIST "/" *
* LIST () "/" "INBOX"
* LIST (\Noselect) "/" "[Gmail]"
* LIST () "/" "[Gmail]/All Mail"
* LIST () "/" "[Gmail]/Drafts"
* LIST () "/" "[Gmail]/Sent Mail"
* LIST () "/" "[Gmail]/Spam"
* LIST () "/" "[Gmail]/Starred"
* LIST () "/" "[Gmail]/Trash"
02 OK Success
03 LOGOUT
* BYE LOGOUT Requested
03 OK 73 good day (Success)
read:errno=0
Ping Results:
***This is probably where the problem lies:***
PEAR_Error Object
(
    [error_message_prefix] =>
    [mode] => 1
    [level] => 1024
    [code] => 1
    [message] => unknown host
    [userinfo] =>
    [backtrace] => Array
        (
            [0] => Array
                (
                    [file] => /usr/lib/php/PEAR.php
                    [line] => 572
                    [function] => PEAR_Error
                    [class] => PEAR_Error
                    [type] => ->
                    [args] => Array
                        (
                            [0] => unknown host
                            [1] => 1
                            [2] => 1
                            [3] => 1024
                            [4] =>
                        )

                )

            [1] => Array
                (
                    [file] => /Net/Ping.php
                    [line] => 394
                    [function] => raiseError
                    [class] => PEAR
                    [type] => ->
                    [args] => Array
                        (
                            [0] => unknown host
                            [1] => 1
                        )

                )

            [2] => Array
                (
                    [file] => /mail.php
                    [line] => 44
                    [function] => ping
                    [class] => Net_Ping
                    [type] => ->
                    [args] => Array (5,32,512)
                        (
                            [0] => imap.google.com
                        )

                )

        )

    [callback] =>
)

PHP_INFO IMAP:

IMAP c-Client Version              -       2001
SSL Support                         -           enabled
Kerberos Support                -       enabled


IMAP Errors:

I can't get any sort of value from these due to the IMAP_LAST_ERROR().


ERROR_LOG:

[01-Dec-2007 19:04:04] PHP Warning:  imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /mail.php on line 3
I meant a ping command from a command window.  In nix, this is a shell command line.  In Windows, this is cmd.exe window.

What version of PHP are you using?
Did you try the openssl s_client test (preferably from the same server running the PHP script)?
Does your code work if you use the IP instead of imap.gmail.com (I get 64.233.185.109)?

I'm not sure that PEAR has anything to do with it, but I'm looking.  The IMAP documentation in PHP has not mentioned anything about it that I've seen.

So far, everything is pointing back to your being unable to resolve the server.  
If the ping test does not work, try a manual nslookup session.
Here's the result when i ping imap.google.com:
-bash-3.00$ ping imap.google.com
ping: unknown host imap.google.com

Here's the result when i ping 64.233.185.109:
64 bytes from 64.233.185.109: icmp_seq=1 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=2 ttl=249 time=24.3 ms
64 bytes from 64.233.185.109: icmp_seq=3 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=4 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=5 ttl=249 time=25.8 ms
64 bytes from 64.233.185.109: icmp_seq=6 ttl=249 time=26.8 ms
64 bytes from 64.233.185.109: icmp_seq=7 ttl=249 time=27.6 ms
64 bytes from 64.233.185.109: icmp_seq=8 ttl=249 time=28.0 ms
64 bytes from 64.233.185.109: icmp_seq=9 ttl=249 time=26.4 ms
64 bytes from 64.233.185.109: icmp_seq=10 ttl=249 time=27.4 ms
64 bytes from 64.233.185.109: icmp_seq=11 ttl=249 time=26.7 ms
64 bytes from 64.233.185.109: icmp_seq=12 ttl=249 time=27.9 ms
64 bytes from 64.233.185.109: icmp_seq=13 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=14 ttl=249 time=26.9 ms
64 bytes from 64.233.185.109: icmp_seq=15 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=16 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=17 ttl=249 time=24.3 ms
64 bytes from 64.233.185.109: icmp_seq=18 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=19 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=20 ttl=249 time=24.6 ms
64 bytes from 64.233.185.109: icmp_seq=21 ttl=249 time=26.7 ms
64 bytes from 64.233.185.109: icmp_seq=22 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=23 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=24 ttl=249 time=24.5 ms
64 bytes from 64.233.185.109: icmp_seq=25 ttl=249 time=26.1 ms
64 bytes from 64.233.185.109: icmp_seq=26 ttl=249 time=26.6 ms
64 bytes from 64.233.185.109: icmp_seq=27 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=28 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=29 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=30 ttl=249 time=27.9 ms
64 bytes from 64.233.185.109: icmp_seq=31 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=32 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=33 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=34 ttl=249 time=23.9 ms
64 bytes from 64.233.185.109: icmp_seq=35 ttl=249 time=24.6 ms
64 bytes from 64.233.185.109: icmp_seq=36 ttl=249 time=23.9 ms
64 bytes from 64.233.185.109: icmp_seq=37 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=38 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=39 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=40 ttl=249 time=26.7 ms
64 bytes from 64.233.185.109: icmp_seq=41 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=42 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=43 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=44 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=45 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=46 ttl=249 time=26.4 ms
64 bytes from 64.233.185.109: icmp_seq=47 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=48 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=49 ttl=249 time=26.7 ms
64 bytes from 64.233.185.109: icmp_seq=50 ttl=249 time=24.6 ms
64 bytes from 64.233.185.109: icmp_seq=51 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=52 ttl=249 time=26.4 ms
64 bytes from 64.233.185.109: icmp_seq=53 ttl=249 time=24.9 ms
64 bytes from 64.233.185.109: icmp_seq=54 ttl=249 time=24.1 ms
64 bytes from 64.233.185.109: icmp_seq=55 ttl=249 time=25.3 ms
64 bytes from 64.233.185.109: icmp_seq=56 ttl=249 time=24.9 ms
64 bytes from 64.233.185.109: icmp_seq=57 ttl=249 time=26.4 ms
64 bytes from 64.233.185.109: icmp_seq=58 ttl=249 time=24.0 ms
64 bytes from 64.233.185.109: icmp_seq=59 ttl=249 time=27.9 ms
64 bytes from 64.233.185.109: icmp_seq=60 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=61 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=62 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=63 ttl=249 time=23.7 ms
64 bytes from 64.233.185.109: icmp_seq=64 ttl=249 time=24.8 ms
64 bytes from 64.233.185.109: icmp_seq=65 ttl=249 time=26.1 ms
64 bytes from 64.233.185.109: icmp_seq=66 ttl=249 time=26.6 ms
64 bytes from 64.233.185.109: icmp_seq=67 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=68 ttl=249 time=27.0 ms
64 bytes from 64.233.185.109: icmp_seq=69 ttl=249 time=27.3 ms
64 bytes from 64.233.185.109: icmp_seq=70 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=71 ttl=249 time=23.8 ms
64 bytes from 64.233.185.109: icmp_seq=72 ttl=249 time=23.6 ms
64 bytes from 64.233.185.109: icmp_seq=73 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=74 ttl=249 time=26.6 ms
64 bytes from 64.233.185.109: icmp_seq=75 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=76 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=77 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=78 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=79 ttl=249 time=27.6 ms
64 bytes from 64.233.185.109: icmp_seq=80 ttl=249 time=23.8 ms
64 bytes from 64.233.185.109: icmp_seq=81 ttl=249 time=24.9 ms
64 bytes from 64.233.185.109: icmp_seq=82 ttl=249 time=27.3 ms
64 bytes from 64.233.185.109: icmp_seq=83 ttl=249 time=26.6 ms
64 bytes from 64.233.185.109: icmp_seq=84 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=85 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=86 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=87 ttl=249 time=23.9 ms
64 bytes from 64.233.185.109: icmp_seq=88 ttl=249 time=26.0 ms
64 bytes from 64.233.185.109: icmp_seq=89 ttl=249 time=26.0 ms
64 bytes from 64.233.185.109: icmp_seq=90 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=91 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=92 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=93 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=94 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=95 ttl=249 time=24.5 ms
64 bytes from 64.233.185.109: icmp_seq=96 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=97 ttl=249 time=24.1 ms
64 bytes from 64.233.185.109: icmp_seq=98 ttl=249 time=25.3 ms
64 bytes from 64.233.185.109: icmp_seq=99 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=100 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=101 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=102 ttl=249 time=27.1 ms
64 bytes from 64.233.185.109: icmp_seq=103 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=104 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=105 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=106 ttl=249 time=25.8 ms
64 bytes from 64.233.185.109: icmp_seq=107 ttl=249 time=23.8 ms
64 bytes from 64.233.185.109: icmp_seq=108 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=109 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=110 ttl=249 time=24.3 ms
64 bytes from 64.233.185.109: icmp_seq=111 ttl=249 time=25.3 ms
64 bytes from 64.233.185.109: icmp_seq=112 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=113 ttl=249 time=26.0 ms
64 bytes from 64.233.185.109: icmp_seq=114 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=115 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=116 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=117 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=118 ttl=249 time=24.1 ms
64 bytes from 64.233.185.109: icmp_seq=119 ttl=249 time=24.6 ms
64 bytes from 64.233.185.109: icmp_seq=120 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=121 ttl=249 time=24.3 ms
64 bytes from 64.233.185.109: icmp_seq=122 ttl=249 time=28.1 ms
64 bytes from 64.233.185.109: icmp_seq=123 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=124 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=125 ttl=249 time=25.3 ms
64 bytes from 64.233.185.109: icmp_seq=126 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=127 ttl=249 time=27.1 ms
64 bytes from 64.233.185.109: icmp_seq=128 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=129 ttl=249 time=23.9 ms
64 bytes from 64.233.185.109: icmp_seq=130 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=131 ttl=249 time=26.7 ms
64 bytes from 64.233.185.109: icmp_seq=132 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=133 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=134 ttl=249 time=23.7 ms
64 bytes from 64.233.185.109: icmp_seq=135 ttl=249 time=24.0 ms
64 bytes from 64.233.185.109: icmp_seq=136 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=137 ttl=249 time=24.8 ms
64 bytes from 64.233.185.109: icmp_seq=138 ttl=249 time=28.6 ms
64 bytes from 64.233.185.109: icmp_seq=139 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=140 ttl=249 time=24.3 ms
64 bytes from 64.233.185.109: icmp_seq=141 ttl=249 time=26.1 ms
64 bytes from 64.233.185.109: icmp_seq=142 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=143 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=144 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=145 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=146 ttl=249 time=25.9 ms
64 bytes from 64.233.185.109: icmp_seq=147 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=148 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=149 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=150 ttl=249 time=23.9 ms
64 bytes from 64.233.185.109: icmp_seq=151 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=152 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=153 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=154 ttl=249 time=24.9 ms
64 bytes from 64.233.185.109: icmp_seq=155 ttl=249 time=24.1 ms
64 bytes from 64.233.185.109: icmp_seq=156 ttl=249 time=27.2 ms
64 bytes from 64.233.185.109: icmp_seq=157 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=158 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=159 ttl=249 time=25.3 ms
64 bytes from 64.233.185.109: icmp_seq=160 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=161 ttl=249 time=25.3 ms
64 bytes from 64.233.185.109: icmp_seq=162 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=163 ttl=249 time=26.1 ms
64 bytes from 64.233.185.109: icmp_seq=164 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=165 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=166 ttl=249 time=25.8 ms
64 bytes from 64.233.185.109: icmp_seq=167 ttl=249 time=24.3 ms
64 bytes from 64.233.185.109: icmp_seq=168 ttl=249 time=25.6 ms
64 bytes from 64.233.185.109: icmp_seq=169 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=170 ttl=249 time=24.3 ms
64 bytes from 64.233.185.109: icmp_seq=171 ttl=249 time=24.0 ms
64 bytes from 64.233.185.109: icmp_seq=172 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=173 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=174 ttl=249 time=25.4 ms
64 bytes from 64.233.185.109: icmp_seq=175 ttl=249 time=28.1 ms
64 bytes from 64.233.185.109: icmp_seq=176 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=177 ttl=249 time=26.2 ms
64 bytes from 64.233.185.109: icmp_seq=178 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=179 ttl=249 time=25.7 ms
64 bytes from 64.233.185.109: icmp_seq=180 ttl=249 time=27.5 ms
64 bytes from 64.233.185.109: icmp_seq=181 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=182 ttl=249 time=26.9 ms
64 bytes from 64.233.185.109: icmp_seq=183 ttl=249 time=24.0 ms
64 bytes from 64.233.185.109: icmp_seq=184 ttl=249 time=25.5 ms
64 bytes from 64.233.185.109: icmp_seq=185 ttl=249 time=26.1 ms
64 bytes from 64.233.185.109: icmp_seq=186 ttl=249 time=25.3 ms
64 bytes from 64.233.185.109: icmp_seq=187 ttl=249 time=25.0 ms
64 bytes from 64.233.185.109: icmp_seq=188 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=189 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=190 ttl=249 time=26.0 ms
64 bytes from 64.233.185.109: icmp_seq=191 ttl=249 time=24.7 ms
64 bytes from 64.233.185.109: icmp_seq=192 ttl=249 time=24.8 ms
64 bytes from 64.233.185.109: icmp_seq=193 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=194 ttl=249 time=26.6 ms
64 bytes from 64.233.185.109: icmp_seq=195 ttl=249 time=23.7 ms
64 bytes from 64.233.185.109: icmp_seq=196 ttl=249 time=26.0 ms
64 bytes from 64.233.185.109: icmp_seq=197 ttl=249 time=25.2 ms
64 bytes from 64.233.185.109: icmp_seq=198 ttl=249 time=26.9 ms
64 bytes from 64.233.185.109: icmp_seq=199 ttl=249 time=25.1 ms
64 bytes from 64.233.185.109: icmp_seq=200 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=201 ttl=249 time=23.9 ms
64 bytes from 64.233.185.109: icmp_seq=202 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=203 ttl=249 time=26.7 ms
64 bytes from 64.233.185.109: icmp_seq=204 ttl=249 time=24.5 ms
64 bytes from 64.233.185.109: icmp_seq=205 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=206 ttl=249 time=26.3 ms
64 bytes from 64.233.185.109: icmp_seq=207 ttl=249 time=24.2 ms
64 bytes from 64.233.185.109: icmp_seq=208 ttl=249 time=24.1 ms
64 bytes from 64.233.185.109: icmp_seq=209 ttl=249 time=27.2 ms
64 bytes from 64.233.185.109: icmp_seq=210 ttl=249 time=24.0 ms
64 bytes from 64.233.185.109: icmp_seq=211 ttl=249 time=26.4 ms
64 bytes from 64.233.185.109: icmp_seq=212 ttl=249 time=26.5 ms
64 bytes from 64.233.185.109: icmp_seq=213 ttl=249 time=24.4 ms
64 bytes from 64.233.185.109: icmp_seq=214 ttl=249 time=23.8 ms

--- 64.233.185.109 ping statistics ---
215 packets transmitted, 215 received, 0% packet loss, time 214562ms


PHP - Version 5.2.0
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You know what. You are pinging imap.gmail.com. I've been pinging imap.google.com. When I ping imap.gmail.com, I do get a response.

-bash-3.00$ ping imap.gmail.com -c 20
PING gmail-imap.l.google.com (72.14.247.109) 56(84) bytes of data.
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=0 ttl=248 time=24.                             5 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=1 ttl=248 time=26.                             9 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=2 ttl=248 time=27.                             0 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=3 ttl=248 time=24.                             8 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=4 ttl=248 time=29.                             5 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=5 ttl=248 time=25.                             6 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=6 ttl=248 time=27.                             3 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=7 ttl=248 time=27.                             3 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=8 ttl=248 time=28.1 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=9 ttl=248 time=25.8 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=10 ttl=248 time=27.3 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=11 ttl=248 time=28.2 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=12 ttl=248 time=25.6 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=13 ttl=248 time=27.4 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=14 ttl=248 time=24.8 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=15 ttl=248 time=26.9 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=16 ttl=248 time=27.8 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=17 ttl=248 time=25.9 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=18 ttl=248 time=27.3 ms
64 bytes from ag-in-f109.google.com (72.14.247.109): icmp_seq=19 ttl=248 time=27.5 ms

--- gmail-imap.l.google.com ping statistics ---
20 packets transmitted, 20 received, 0% packet loss, time 19107ms


So what does this mean? Do we start back from the beginning? Should I still try to post in DNS? Even though I was pinging the wrong address, the address in the script is correct. I'm still getting the same error.
My host has responded telling me they have added a firewall rule that allows outbound to gmail! thanks for all your help!
>>> You are pinging imap.gmail.com. I've been pinging imap.google.com.

LOL!  I can't believe I didn't catch that...I made the same mistake during some my tests, too.

>>> When I ping imap.gmail.com, I do get a response.

I was kind of curious about that until...

>>> My host has responded telling me they have added a firewall rule that allows outbound to gmail!

That makes more sense now.  Many ISPs block port 25 (outbound SMTP) as a general rule, but I haven't heard of too many blocking IMAP/S or POP/S.  I'm glad you were able to get it resolved.  Good luck!