PHP Doku:: Öffnet eine Verbindung zu einem Mailserver-Postfach - function.imap-open.html

Verlauf / Chronik / History: (18) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzE-Mail-relevante ErweiterungenIMAP, POP3 and NNTPIMAP Funktionenimap_open

Ein Service von Reinhard Neidl - Webprogrammierung.

IMAP Funktionen

<<imap_num_recent

imap_ping>>

imap_open

(PHP 4, PHP 5)

imap_openÖffnet eine Verbindung zu einem Mailserver-Postfach

Beschreibung

resource imap_open ( string $mailbox , string $username , string $password [, int $options = NIL [, int $n_retries = 0 ]] )

Öffnet eine Verbindung zum Postfach mailbox.

Diese Funktion kann neben IMAP auch POP3 und NNTP Verbindungen aufbauen, einige Funktionen und Eigenschaften sind aber nur in IMAP Verbindungen verfügbar.

Parameter-Liste

mailbox

Ein Postfachname besteht aus einer Angabe des Servers und aus dem Pfad zum Postfach auf diesem Server. Der reservierte Name INBOX steht für das persönliche Postfach des aktuellen Benutzers. Enthält der Name des Postfach internationale Zeichen außerhalb des druckbaren ASCII Bereichs so müssen diese mit imap_utf7_encode() kodiert werden.

Der Serverteil wird in '{' und '}' eingebettet, er besteht aus dem Namen oder der IP-Adresse des Servers, einer optionalen Portnummer (eingeleitet mit ':' und einer optionalen Protokollangabe (eingeleitet mit '/').

Die Angabe des Serverteils ist immer zwingend.

Alle Namen die mit { beginnen bezeichnen Serverdienste und werden in der Form "{" remote_system_name [":" port] [flags] "}" angegeben:

  • remote_system_name - DNS Servername oder IP-Adresse des Servers in eckigen Klammern
  • port - optionale Portnummer, Standard ist der jeweilige Standardport des gewählten Protokolls
  • flags - Optionsflags, s.u.
  • mailbox_name - Name des gewünschten Serverpostfachs, Standard ist "INBOX"

Optional flags for names
Flag Description
/service=service Postfach-Zugriffsprotokoll, Standard ist "imap"
/user=user Benutzername auf dem Mailserver
/authuser=user remote authentication user; if specified this is the user name whose password is used (e.g. administrator)
/anonymous Zugriff als anonymer Benutzer
/debug Protokollausgaben in das Fehlerlog des Webservers leiten
/secure Übertragung von Klartext-Passwörtern wird verhindert
/imap, /imap2, /imap2bis, /imap4, /imap4rev1 Kurzform für /service=imap
/pop3 Kurzform für /service=pop3
/nntp Kurzform für /service=nntp
/norsh Für eine vorauthentifizierte IMAP Verbindung soll weder rsh noch ssh verwendet werden
/ssl Secure Socket Layer (SSL) zur Verschlüsselung der Verbindung verwenden
/validate-cert TLS/SSL Zertifikate verifizieren (Standardverhalten)
/novalidate-cert TLS/SSL Zertifikate nicht verifizieren, wird für selbstsignierte Zertifikate benötigt
/tls start-TLS Verschlüsselung erzwingen, Verbindungen von Servern die dies nicht unterstützen ablehnen.
/notls start-TLS nicht verwenden, auch wenn es der Server unterstützt
/readonly Nur lesender Zugriff auf den Server ohne serverseitige Änderung von Daten (nur für IMAP, NNTP ignoriert dies, POP3 und SMTP verweigern readonly Verbindungen)

username

Der Benutzername

password

Das Passwort zum Benutzernamen

options

Der Parameter options kann sich als Bitmaske aus folgenden Werten zusammensetzen:

  • OP_READONLY - Nur lesende Zugriffe
  • OP_ANONYMOUS - ein existierendes .newsrc weder lesen noch aktualisieren (nur NNTP)
  • OP_HALFOPEN - Verbindung zum Server öffnen aber noch kein Postfach auswählen (nur IMAP und NNTP)
  • CL_EXPUNGE - Zum löschen markierte Nachrichten beim Schließen des Postfachs automatisch entfernen (siehe auch imap_delete() und imap_expunge())
  • OP_DEBUG - Debug Protokoll
  • OP_SHORTCACHE - verkürztes Cacheing
  • OP_SILENT - Ereignisse nicht weitergeben (interne Einstellung)
  • OP_PROTOTYPE - Driver Prototyp zurückgeben
  • OP_SECURE - Authentifikation nicht absichern

n_retries

Maximale Anzahl Verbindungsversuche

Rückgabewerte

Liefert einen IMAP Stream oder FALSE bei Fehlern.

Changelog

Version Beschreibung
5.2.0 n_retries hinzugefügt

Beispiele

Beispiel #1 Verschiedene imap_open() Aufrufe

<?php
// Verbindung zu einem IMAP server auf Port 143 des lokalen Rechners 
$mbox imap_open("{localhost:143}INBOX""user_id""password");

// Verbindung zu einem POP3 server auf Port 110 des lokalen Rechners 
$mbox imap_open ("{localhost:110/pop3}INBOX""user_id""password");

// Für SSL verschlüsselte Verbindungen wird /ssl an die 
// Protokollspezifikation angefügt
$mbox imap_open ("{localhost:993/imap/ssl}INBOX""user_id""password");

// Zur SSL Verbindung mit Servern mit selbstsignierten Zertifikaten 
// muss zusätzlich /novalidate-cert angefügt werden
$mbox imap_open ("{localhost:995/pop3/ssl/novalidate-cert}""user_id""password");

// Verbindung zu einem NNTP server auf Port 119 des lokalen Rechners 
$nntp imap_open ("{localhost:119/nntp}comp.test""""");

// Für Verbindungen zu anderen Servern ersetzen Sie "localhost" mit
// dem Namen oder der IP-Adresse des Servers
?>

Beispiel #2 imap_open() Beispiel

<?php
$mbox 
imap_open("{imap.example.org:143}""username""password");

echo 
"<h1>Postfächer</h1>\n";
$folders imap_listmailbox($mbox"{imap.example.org:143}""*");

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

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

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

imap_close($mbox);
?>

Siehe auch


50 BenutzerBeiträge:
- Beiträge aktualisieren...
guilherme dot geronimo at gmail dot com
10.11.2010 2:23
Using:
<?php
imap_open
( "{server.example.com:143}INBOX" , 'login' , 'password' );
?>

Got this error:
"Couldn't open stream {server.example.com:143}INBOX"

Solved by adding the flag "novalidate-cert":
<?php
imap_open
( "{server.example.com:143/novalidate-cert}INBOX" , 'login' , 'password' );
?>

=D
egoman69 at hotmail
7.09.2010 21:32
"Couldn't open stream {127.0.0.1:143/imap/notls}INBOX"

Solved by only replacing 127.0.0.1 with localhost, php and IMAP server both in same machine, not through Proxy or anything. Weird!
Nohado
26.08.2010 8:34
if u ever get something like this:

Notice: Unknown: IMAP protocol error: Invalid system flag in Store command (errflg=2) in Unknown on line 0

Notice: Unknown: Invalid system flag in Store command (errflg=2) in Unknown on line 0

This Error occurs if u want to set a flag 2 times. Just check ur manually flag Settings.

Cheers,
Nohado
anthony2009 at ns dot sympatico dot ca
25.08.2010 21:34
<?php
// You can break out the variables for $mailserver, $port, $user and
// $pass without passing brackets into functions this way. Be sure to use
// the dots to append connection strings, ie "stuff". $variable ."STUFF"
// otherwise will go to imap_open with wrong variable type. :)

$mailserver="mail.example.com";
$port="110/pop3";
$user="aj";
$pass="remax01";
 
if (
$mbox=imap_open( "{" . $mailserver . ":" . $port . "}INBOX", $user, $pass ))
 {  echo
"Connected\n";
        
   
$check = imap_mailboxmsginfo($mbox);
         
    echo
"Date: "     . $check->Date    . "<br />\n" ;
    echo
"Driver: "   . $check->Driver  . "<br />\n" ;
    echo
"Unread: "   . $check->Unread  . "<br />\n" ;
    echo
"Size: "     . $check->Size    . "<br />\n" ;
        
   
imap_close($mbox);
 } else { exit (
"Can't connect: " . imap_last_error() ."\n");  echo "FAIL!\n";  };
?>
mydisk6g at gmail dot com
13.05.2010 11:34
Guys, I can't access this pop3 GMail account.
I had read all your comments, I run this on Linux UBUNTU 8.04, GOS.
I had runt it 2years ago on windows xp but the machine crash, if U can help Thks..

<html><head><title>MailTest</title></head><body><h1>Mailtest</h1>
<?php
echo "Loading..."."<br />\n";
 
$mailuser="mydisk6g@gmail.com";

echo
"User=$mailuser"."<br />\n";;
 
$mailpass="mailtest";
echo
"Pass=$mailpass"."<br />\n";
/* Settings: Status:  POP is enabled for all mail that has arrived... */
/* Google say: Incoming Mail (POP3) Server - requires SSL: pop.gmail.com, Use SSL: Yes Port: 995 */
 
$mailhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX";
echo
"Host=$mailhost"."<br />\n";

 
$mailbox=imap_open($mailhost,$mailuser,$mailpass) or die("<br />\nFAILLED! ".imap_last_error());
 
imap_close($mailbox);

echo
"completed.". "<br />\n";;
?>
</body></html>

==>

Mailtest
Loading...
User=mydisk6g@gmail.com
Pass=mailtest
Host={pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX

Warning: imap_open() [function.imap-open]:
Couldn't open stream {pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX
in /home/emailosc/public_html/mailtest.php on line 13

FAILLED! Can't connect to gmail-pop.l.google.com,995:
Connection timed out
oz49erfan
3.03.2010 4:39
Make sure your PHP is enabled with imap via the phpinfo() function

'--with-imap-dir=/opt/lampp' '--with-imap-ssl' '--with-imap=/opt/lampp'

and

IMAP c-Client Version 2007e
SSL Support Yes

I noticed that my apache script was working but my cli script was not. Turns out my php cli executable didn't have imap setup so I had to use another php cli executable.
kay at rrr dot de
31.01.2010 17:16
imap_open is very simple to use, but struggles a litte bit on setups with ssl and tls.

this are tested examples for different hosts and protocols.

uncomment the host/protocol line and fill in correct username and password.

Kay

<?php

#######
# localhost pop3 with and without ssl
# $authhost="{localhost:995/pop3/ssl/novalidate-cert}";
# $authhost="{localhost:110/pop3/notls}";

# localhost imap with and without ssl
# $authhost="{localhost:993/imap/ssl/novalidate-cert}";
# $authhost="{localhost:143/imap/notls}";
# $user="localuser";

# localhost nntp with and without ssl
# you have to specify an existing group, control.cancel should exist
# $authhost="{localhost:563/nntp/ssl/novalidate-cert}control.cancel";
# $authhost="{localhost:119/nntp/notls}control.cancel";

######
# web.de pop3 without ssl
# $authhost="{pop3.web.de:110/pop3/notls}";
# $user="kay.marquardt@web.de";

#########
# goggle with pop3 or imap
# $authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}";
# $authhost="{imap.gmail.com:993/imap/ssl/novalidate-cert}";
# $user="username@gmail.com";

$user="username like above";
$pass="yourpass";

if (
$mbox=imap_open( $authhost, $user, $pass ))
        {
         echo
"<h1>Connected</h1>\n";
        
imap_close($mbox);
        } else
        {
         echo
"<h1>FAIL!</h1>\n";
        }

?>
mightycpa
4.07.2009 7:45
My script kept on timing out, even though the syntax was spot on... ultimately, I figured out that the port was blocked by my webhost, where I ran this on a shared server...

I post this just in case you miss this obvious, like I did.
bjtjong at home dot nl
9.12.2008 10:50
To open an email message (*.eml) stored on disk you should add at the start of the message the following line:

From dummy@localhost  Sat Jan  1 00:00:00 1970

Then with imap_open("path/file.eml","","") you can process the email message as usal
Jason Pires
25.04.2008 19:56
Dears.
In my case, e-mail host was the IMAP enabled.
So, just use the imap_open as the very simple form like:

$mailbox = "{mail.myhost.com:143/notls}INBOX";
$user = "me@myhost.com";
$pass = "mypassword";

$connection = imap_open($mailbox,$user,$pass) or die(imap_last_error()."<br>Connection Faliure!");

thanks!
Binit
11.04.2008 23:39
I was trying imap_open() function but I was continuously getting this error:

Array ( [0] => [CLOSED] IMAP connection broken (server response) )

I was finally able to solve this problem (which is a very common problem as I saw it on the net but could not find any solution to it) so I'm posting my solution here which I hope will be useful to others.

I used stunnel program (http://www.stunnel.org/) and made changes in the stunnel.conf file as follows:

I added these lines:
[imapsClient]
accept = localhost:143
connect  = imapserver:993
client = yes
sslVersion = TLSv1

This will map insecure imap connection from localhost:143 to imapserver:993 (IMAP with SSL).

After this I tried this code and it worked fine:

<?php

$user
="";
$pass="";
$imap = @imap_open("{localhost:143}INBOX", $user, $pass);
?>

and I was able to do away with the errors.

A more detailed post about it can be found here:
http://www.phpfreaks.com/forums/index.php/topic,190628.0.html
itstooloud
31.10.2007 20:50
Works with Gmail's new IMAP function for personal and for Google Apps.

$mbox = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", "username@gmail.com", "password")
     or die("can't connect: " . imap_last_error());
rhaft22 at gmail dot com
4.10.2007 3:29
The following works for connecting via POP3 to a gmail server:
imap_open("{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX", $username, $pasword);
askalski at synacor dot com
27.09.2007 17:50
By default, imap_open() will retry an incorrect password 3 times before giving up.  This is a feature built into the c-client library intended for interactive mail clients (which can prompt the end user for a new username/password combo.)

The new optional parameter "$n_retries" allows PHP to override the default retry limit.  There is absolutely no reason to leave this at default, or to set it to any value other than 1.  This is especially important if the mail server you're using locks users out after too many login failures.
bow+php dot net at virtual-habitat dot net
8.09.2007 17:06
Setting a mailbox name (eg INBOX) at the end of the connection string does not work when using imap_open() with OP_HALFOPEN. You may use imap_reopen() then.

<?php

/* this will fail : */
$connection = imap_open('{mx.example.net}INBOX', 'foo', 'secret', OP_HALFOPEN.);
$num_mgs = imap_num_msg($connection);
imap_close($connection);

/* this will do : */
$connection = imap_open('{mx.example.net}INBOX', 'foo', 'secret', OP_HALFOPEN.);
imap_reopen($connection, '{mx.example.net}INBOX');
$num_mgs = imap_num_msg($connection);
imap_close($connection);

?>
gyokimae
11.05.2007 8:11
Beginning with 5.2.2, binaries built for Windows also seem to have changed its default behavior.
'/notls' needs to be specified for a non-SSL connection.
Fladnag
27.02.2007 10:08
you can avoid this message :

Warning: (null)(); Mailbox is empty (errflg=1) in Unknown on line 0

by specified the option OP_SILENT to imap_open.
Amit
11.09.2006 19:25
None of the above comments explain the configuration issues on Apache/Windows combination. I thought it might be helpful to list my findings here so that Windows people's time is saved.

There is a bug in Windows php_imap.dll that prevents it from connecting it to the SSL IMAP/POP3 server.

http://bugs.php.net/bug.php?id=36496&edit=1
shaikh_zaid at yahoo dot com
4.04.2006 20:55
imap_open will not open a stream if your server operates with Transport Layer Security (i.e. TLS) imap_open connects with SSL if its there. So try opening mailbox as

$mailbox="{mail.domain.com:143/imap/notls}";
or
$mailbox="{mail.domain.com:110/pop3/notls}"; This works...

Some mail server requires you to provide username@domain.com so you can always use. user@doamin.com

$conn=imap_open($mailbox, $username, $password);

Some server may ask for username as "user=user@domain.com"

:)
admin at sellchain dot com
9.12.2005 5:36
Looking for a cool PHP Script to help you connect to a POP3 server, and download E-Mail to MySQL? Check out my neet-skeet script I wrote. Have fun.

Http://www.sellchain.com/phPOP3/phPOP3.txt

Download the above TXT file, and rename it to phPOP3.php.

Trust me, you will learn mostly everything about IMAP with this script.

By the way, be sure to use print_r($headers) to discover the headers that come with each message. You can setup your MySQL + Email Account information at the top of the script. No includes required!

Enjoyz;)

3.08.2005 4:13
WHen you use the /ssl connection...  half open doesnt work...!

what i did was opened it up with the .com:143/pop3}, op_halfopen

when i was getting my folders...
avizion at relay dot dk
12.05.2005 12:30
For FreeBSD users...

If you want to have SSL support, you want to install the ports:

mail/php5-imap
security/php5-openssl

Cheers :)

 - avizion
m dot stoel at cyberkinetic dot nl
27.04.2005 19:50
a little tip for those who get really frustrated even after reading all the right solutions and implementing them but still get the same errors or none at all..:
after having changed the code.. restart the httpd deamon..

for Fedora or any other Red Hat Linux OS (/etc/init.d/httpd restart).

After this you will be able to make a imap/pop3 stream from apache..
thushara dot perera at unilink dot lk
26.02.2005 6:19
Warning: imap_open() [function.imap-open]: Couldn't open stream {xx.xx.x.xxx:143}INBOX

correct the connection string as :
{xx.xx.x.xxx:143/notls}INBOX
info at infosoporte.com
25.02.2005 3:14
I can connect to my email server with no problem using regular usernames and passwords but.... in my server the usernames are long.. like name.surname1.surname2@subdomain.domain.com , and i get an error when the username size is over 40 chars:

$conn = imap_open("{". $server . ":110/pop3}", $username, $user_password) or die ("Failed with error: ".imap_last_error());

returns

Too many login failures

when the username is over 40 chars. Just remember that if you plan to use long usernames.
elizar.palad
14.12.2004 7:22
thanks to the one who added that the login part should be the whole email address for it to work.. (assuming of course that all other stuff is good and working ;)

to add something, in the 'email address' login name, is not really the email address, ,it's the pop login name plus '@' plus the domain.. hope it's not confusing...

poploginname@domain.com

not

emailaddress@domain.com..
gasaunde at vcu dot edu
13.12.2004 20:35
I've found that on my servers I _must_ use imap_errors() and imap_alerts() after an imap_open or this error is thrown in the logs when the mailbox is empty: [error] PHP Warning: (null)(); Mailbox is empty (errflg=1) in Unknown on line 0
cg at compile dot ch
20.09.2004 14:16
If you use cyrus, passwords shadow via saslauth, check this:

> =====IMAPD.conf======
> configdirectory:        /var/imap
> partition-default:      /var/spool/imap
> sievedir:               /var/imap/sieve
> tls_cert_file:          /etc/cyrusimapd/server.crt
> tls_key_file:           /etc/cyrusimapd/server.key
> admins:                 cyrus
> hashimapspool:          yes
> allowanonymouslogin:    no
> allowplaintext:         yes
> unixhierarchysep:       0
> servername:             mail.garage.com
> sasl_pwcheck_method:    saslauthd
> mech_list: plain login

Make this

sasl_mech_list: plain login
liamr at umich dot edu
30.06.2004 1:40
To authenticate using kerberos V / GSSAPI, you might need to add "user=" to the connection string.. eg:

$mbox = imap_open( "\{imap.example.com:143/imap/notls/user=" . $user . "}INBOX", $user, $passwd );

Our IMAP servers won't allow a user other than the user specified in the kerberos credentials connect using those credentials unless you specify that extra "user=" in the connection string.  Passing it as an argument to imap_open() doesn't seem to be enough.
nmmm at nmmm dot nu
22.06.2004 19:37
To open local mailbox ( mbox ) enter its absolute file name.

>an absolute filename
>This specifies a mailbox in the default format (usually >Berkeley format for most default library builds)

source:
http://aspn.activestate.com/ASPN/CodeDoc/Mail-Cclient/Cclient.html
rvarkelen AT hortimax.nl
14.01.2004 12:03
In order to make a IMAP connection to a Microsoft Exchange Server 5.5, I used this connection-string :

<?php
if(imap_open ("{192.168.1.6:143/imap}Inbox", "DOMAIN/USERNAME/ALIAS", "PASSWORD"))
{
    echo
'Connection success!';
}
else
{
    echo
'Connection failed';
}
?>

By replacing "Inbox" with, e.g. "Tasks", its possible to see all your tasks. I Hope this helps anybody!

Regards
marshall /AT pacdemon.org
3.11.2003 20:50
Thanks for all your comments.  The user comments have saved me countless times.

I'd like to give back in my small way by providing this little tip.  To test your pop or imap services you can use telnet (almost all operating systems should come with a command line telnet client).

Here's the pop3 example (the lines that start with + are the server's response):

    telnet your.pop.host.com 110
    +OK POP3 your.pop.host.com v2001.78 server ready
    user your_username
    +OK User name accepted, password please
    pass your_password
    +OK Mailbox open, 23 messages

Note that your pop server may be on some other port than 110 but that is the default/standard.

Here's the imap example (Lines that have OK near the begining are server responses):

    telnet your.imap.host.com 143
    * OK [CAPABILITY IMAP4REV1...]
    1 LOGIN "your_username" "your_password"
    1 OK [CAPABILITY...] ... User your_username authenticated

This might be old news to some people but I hope it's helpful for many.
marshall /at/ sprux net
19.08.2003 1:44
I only run imap on port 993 (ssl only) and I was unable to use imap_open().. couldn't even get an error out of the script, it just sat there and timed out with no messages in the logs or anything--the page wouldn't load.

Anyway, this is what finally worked, which I found in the readme for a popular opensource webmail system:

$i = @imap_open("{localhost:993/ssl/novalidate-cert}INBOX", $user, $pw);

I didn't see the 'ssl' option mentioned anywhere in these comments so maybe this will help someone out.
Kyle Putnam
15.06.2003 1:52
I was getting bizzare errors that I couldn't find documentation about anywhere on Google. I tried connecting to another server and got different, but just as unusual error messages. I even checked the POP3 server logs and it said something about invalid command... I figured it was another libc problem.

Stupidly enough, the problem was that I was using an unset variable for the password! Make sure you don't have an empty username or password... you'll have a hard time debugging the problem ;)
stefan dot greifeneder at dioezese-linz dot at
9.05.2003 3:10
Had problems to use imap_open with iMail 6.06 Server. My problem was (sounds stupid): Didn't realise that the username had to be the full email address and not just the login. Maybe this helps some people.
bill dot mccoy at pictureiq dot com
24.04.2003 4:29
"notls" seems to be required for PHP on RedHat 8.0, but it seems that "/norsh" is also advisable; without it, the client library will attempt an RSH connection and wait for this to timeout before reverting to normal IMAP. This was causing a 15 second delay in imap_open for me. Looking at the client lib C code this will likely be an issue on other platforms as well as they update to the newer version. You can use both "/notls" and "/norsh", e.g. the first parameter to imap_open can be something like: "{your.imap.host/imap/notls/norsh}".
kaper at nexgc dot com
8.04.2003 18:17
I had been having lots of trouble trying to get imap_open to connect to an imap server.  Then I found another post online that suggested this and it worked, so I am going to post it here.  I hope this helps others..

"I have tried with the following strings instead and it works:

for pop3: {www.server.com:110/pop3/notls}INBOX

and for imap: {www.server.com:143/notls}INBOX.
xore at hotmail dot com
2.04.2003 14:37
pop3 seems to like refusing connection if you have OP_READONLY set

testers: be forewarned :P
madsiuk at morellos dot net
27.02.2003 16:35
hi
  Note for all having problems to connect hosts using imap_open:

  I spent almost week trying to fix my script which was connecting to localhost but was unable to connect any other host. Sollution was actually wery simple but I'm writing that note becouse there are some posts at usenet or forums decribing similiar problems. And actually I haven't found any  answer for that. So for all of you trying to connect to hosts with imap_open CHECK IF THERE IS NO FIREWALL BLOCKING POP3.

madsiuk
russell at flora dot ca
9.01.2003 0:07
Note about "PHP Warning:  Certificate failure"

I'm not sure if this is a RedHat, PHP, or IMAP library issue, but the default for SSL seems to have changed.

You now need to specify "/notls" when you don't want TLS, rather than only needing to specify "/ssl" when you do.

Example: 

"{localhost:143}INBOX"

becomes:

"{localhost:143/notls}INBOX"
jpdalbec at ccNO dot ysuSPAM dot edu
17.06.2002 20:27
I ran into the
PHP Warning:  Certificate failure for <server>: self signed certificate:
message while upgrading 4.0.6->4.1.2.  I'm pleased to report that {<server>:<port>/imap/tls/novalidate-cert}<mailbox>
works as expected (and fixes my problem).  I'm using IMP 2.2.8.
fxbois at free dot fr
5.06.2002 20:07
Hi,
I just want to say to all redhat people who have problem (Couldn't open stream) with the connection on the local pop server to use this :
{127.0.0.1:110/pop3/notls}INBOX
hope this help
frederik at roal dot no
17.04.2002 18:02
For all imap functions where you specify the mailbox string it is important that you ALWAYS use IP (not hostname) and the portnumber. If you do not do this imap functions will be painfully slow.
Using hostname instead of IP adds 3 seconds to each IMAP call, not using portnumber adds 10 seconds to each imap call. (hint: use gethostbyname() )
brojann at netscape dot com
30.10.2001 23:01
You can do

<? $foo = imap_errors(); ?>

to clear unwanted warning messages like 'Mailbox is empty'
jdg11 at po dot cwru dot edu
14.08.2001 0:41
It would be nice to mention that this function does send headers. It makes sense, but it is not obvious. It took me a while to figure it out. I authenticate against a POP3 server, and set a cookie if the authentication validates. At least I wanted to :) But since it sends a header to the server, setcookie() won't work.
curtis at lamere dot net
27.06.2001 1:16
I have found that the syntax for the imap_open command in PHP 4 differs whether you're passing a variable to the imap_open function or declaring the host directly within the function.  If you are passing variables to the imap_open function, the syntax should look like:

$username = "user";
$password = "password";
$mailserver = "mail.somedomina.com:110/imap";

$link = imap_open("\{$mailserver}INBOX",$username,$password);

If you don't include the leading backslash (\) you will not open the stream.  Likewise you cannot pass the curly braces to the function.

If you define the server directly, omit the leading backslash.

$username = "user";
$password = "password";

$link = imap_open("{mail.somedomain.com:110/pop3}",$username,$password)"

I discovered all of this after 3 days of trying to get all of this work on redhat 7.1.

23.05.2001 19:23
A better way to connect to a mail server would be to use uri syntax, for example:

imap://username:password@server.com:143/INBOX/message/part

this is very easy to parse using 'parse_url()'

Remember to keep your username and password hidden if your over an open network
fferreres at joydivision dot com dot ar
29.03.2001 17:12
IMAP, POP and NNTP are ok. But plaintext mailboxes are unmentioned here. You just forget the {part} and go for the file (tested on unix):

$mbox = imap_open ($a_mail_box_file_name_in_home_dir, "", "") || die("Snif...:
".imap_last_error());
kvance at n-link dot net
9.03.2001 22:34
Connections to the IMAP server work without specifying the port number, but they are slow, so specifying the port number is important if you don't want a slow application.
bandpay at hotmail dot com
4.12.2000 21:59
I have a single comment to add about imap_open.
If you want to connect to a news server, without specifying any news gruop, you can use the following:

<?php
$server
= "{news.servername.com/nntp:119}";
$nntp = imap_open($server,"","",OP_HALFOPEN);
?>

and $nntp will become the connection ID.

Regards
//Babak



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)