Solved

Retreiving Email headers with PHP

Posted on 2007-11-30
16
1,074 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:bdichiara
  • 8
  • 7
16 Comments
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
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 ?
0
 
LVL 7

Author Comment

by:bdichiara
Comment Utility
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
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
>>> 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
0
 
LVL 7

Author Comment

by:bdichiara
Comment Utility
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?
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
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.
0
 
LVL 7

Author Comment

by:bdichiara
Comment Utility
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?
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
## 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)
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
## 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
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 7

Author Comment

by:bdichiara
Comment Utility
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
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
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.  
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
If the ping test does not work, try a manual nslookup session.
0
 
LVL 7

Author Comment

by:bdichiara
Comment Utility
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
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
Comment Utility
My ping test is shown below.  The IP is different because the test was done on a different server than last time:

#> ping imap.gmail.com
PING gmail-imap.l.google.com (64.233.179.109) 56(84) bytes of data.
64 bytes from hs-in-f109.google.com (64.233.179.109): icmp_seq=0 ttl=246 time=23.2 ms
64 bytes from hs-in-f109.google.com (64.233.179.109): icmp_seq=1 ttl=246 time=22.9 ms
64 bytes from hs-in-f109.google.com (64.233.179.109): icmp_seq=2 ttl=246 time=23.1 ms

Your server is not resolving the name.  I do not have enough knowledge in this area to help you troubleshoot it, but I'm sure there is someone here who does.  Consider posting a new question in the DNS and Linux Administration zones, pointing back here for reference.  If you have DNS support with your host, I recommend you approach them with this problem.

In the meantime, you have two options for a work-around:

1) in the script, globally replace the name with the IP
2) edit /etc/hosts, and add an entry for imap.gmail.com.  

If their IP ever changes, however, your script will break until you update it.
0
 
LVL 7

Author Comment

by:bdichiara
Comment Utility
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.
0
 
LVL 7

Author Comment

by:bdichiara
Comment Utility
My host has responded telling me they have added a firewall rule that allows outbound to gmail! thanks for all your help!
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
>>> 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!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now