0

I'm not a programmer, so please bear with me. Sorry if this is dumb.

I can create and use php scripts on my website no problem. For the last few days, I've been trying to figure out a way to check my email programmatically. The most common solution seemed to involve connecting using imap_open. Here is an example of just that one line of code:

$mail = imap_open("{mymailserver:110}INBOX", "myname@mydomain.com", "mypassword");

And obviously my mail server, username, and password go between the quotes. Just in that one opening line, the page hangs and eventually gives a 504 Gateway Time-out error.

Thunderbird can connect to my email using the same mail server, port, name and password. If i plug in info from a gmail account, it still hangs and times out. When i run phpinfo it says something about imap enabled (sorry if that's not relevant, i'm not sure).

Network Solutions, who hosts my site, told me that I shouldn't be using scripts to connect to email, but they would look into it if I paid a fee. Any help would be greatly appreciated, as I've been trying this for 20 hrs. Thanks.

GRVPrasad
  • 1,228
  • 1
  • 9
  • 24
JohnF
  • 1
  • Possibly you cannot reach the mailserver because the host does not allow connecting on port 504? If it should be possibly: Did you enter the correct mailserver address? please post ONLY the hostname you are using. Have you read the manual and all comments on the function you are using: https://www.php.net/manual/de/function.imap-open.php – Alexander Dobernig Jan 20 '21 at 08:07
  • Hi Alexander. Yes i am using the correct information. I think so anyway, as I saved it in a text file, and copy and paste out of the text file, and into the variables between the quotes. It's the same information that i used to successfully set up the same email account in Thunderbird. I definitely did not read all that I could about using the function, but I don't think it will work on a site hosted by Network Solutions. I saw another post where somebody was complaining that his "add-ons" stopped working because Network Solutions no longer allows imap_open(). – JohnF Jan 21 '21 at 23:29
  • "I saw another post where somebody was complaining that his "add-ons" stopped working because Network Solutions no longer allows imap_open(). – JohnF 10 hours ago " Then we cannot help you ;-) But you could use e.g. https://www.cloudmailin.com/ - their free plan offers 10.000 emails per month - and the paid plans are also quite affordable. They offer various services they will e.g. POST each incoming email to your server - which should help. DID you contact Network Solutions about that isue yet? You should do this before continueing here! – Alexander Dobernig Jan 22 '21 at 09:40
  • Thanks Alexander. I contacted Network Solutions before posting here. I'm not sure I got knowledgeable responses. I was told not to try using scripts to connect to mail, that it isn't supported, but that they would look into it for me if I paid the engineers a fee. As far as using another email service, that still won't work, as whatever script i run won't be able to connect using imap_open. – JohnF Jan 22 '21 at 22:55
  • No. I did not tell you to use imap_open. I told you to use a alternative solution where the service sends you the email with POST like cloudmailin. POST like in a HTML form. This will work. – Alexander Dobernig Jan 22 '21 at 23:01
  • CloudMailin's servers receive email and convert it to an inbound HTTP POST. Reference: "Cloudmailin - Incoming email for web apps, receive email via HTTP Post in the Cloud - Cloudmailin" https://www.cloudmailin.com – Alexander Dobernig Jan 22 '21 at 23:03
  • That sounds promising. I'll look into that, but it sounds like it could work just fine. Thanks for the tip. – JohnF Jan 22 '21 at 23:42

1 Answers1

0

Port 110 is for POP3. I suggest you try to connect thru port 143 (IMAP)

Please try using the following codes to test (substitute imap.example.com by your mail server say mail.test.com) :

Note: for the username, in your case it may be your email address (xxxx@xxxx.com)

<?php

ini_set('max_execution_time', 300); //300 seconds = 5 minutes 


$mbox = imap_open("{imap.example.com:143}", "username", "password");

echo "<h1>Mailboxes</h1>\n";
$folders = imap_listmailbox($mbox, "{imap.example.com:143}", "*");

if ($folders == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($folders as $val) {
        echo $val . "<br />\n";
    }
}

echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);

if ($headers == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />\n";
    }
}

imap_close($mbox);
?>
Ken Lee
  • 6,985
  • 3
  • 10
  • 29
  • Thanks for the sample script, Ken. Unfortunately, when entering my credentials into it, uploading it, and running it, the page hangs for exactly 60 seconds, and then gives me a Gateway time-out error. Thanks for trying to help. – JohnF Jan 21 '21 at 23:32
  • It is likely that there are two many emails in your mailboxes, in that case please add say ini_set('max_execution_time', 300); //300 seconds = 5 minutes at the top of the script and re-try (I have updated my answer for this too) – Ken Lee Jan 22 '21 at 01:55
  • Ken, there are only 3 emails on that account. I just set it up a few days before posting here. All 3 emails only have a few words in them, sent as a test. I will try your suggestion about setting the time to 300 seconds, and report back if it worked. – JohnF Jan 22 '21 at 22:58
  • I just tried adding that line. Nothing changed. It still hung, then timed out after 1 minute. I appreciate the suggestion though. – JohnF Jan 22 '21 at 23:02
  • Ken, here is a screenshot. As you can see in the image, if I click on a link to "show" pop/imap settings before signing in, it says incoming: pop3 server. The screenshot next to that is what i get after signing in where it shows incoming server type imap. Also i have no idea what that email-out-priv-myregisteredwebsite is. My Thunderbird email program connects just fine using pop3 port 110. Anyway, no matter what I've tried, it always hangs, then times out. Here is the link to my settings. I've blocked the website name: https://www.flickr.com/photos/52623957@N02/50863952083/in/dateposted/ – JohnF Jan 22 '21 at 23:52