Hey,

I am working on a trouble ticket program but I want the user to be able to mail in his ticket if he feels like doing it that way. I started working on a mail program seperately just to try and figure it all out. I am getting all sorts of warnings that I am unfamiliar with so I thought I would try to seek some assistance here.

I made a general HTML login form:


<html>
<body>

<form action="mail.php" method="POST">
Username:<br>
<input type="text" name="username"><br>
Password:<br>
<input type="password" name="password"><br>
Server:<br>
<input type="text" name="server"><br>
<input type="submit" value="Check Mail!">
</form>

</body>
</html>

Then another piece to get the mail for that account and echo it out in an extremely basic way (i know... its just for the trial)


<?php

$link = imap_open($server, $username, $password);
$headers = imap_headers($link);

$count = count($headers);

if($count == 0) {
	echo "<b> You have no mail! </b>";
} else {

for($x = 1; $x < $count; $x ++) {
    $idx=($x-1);

$num = $x;

$header = imap_header($link,$num);

$from = $header[fromaddress];
$subject = $header[Subject];
$body = imap_body($link,$num);

echo "From: $from<br>";
echo "Subject: $subject<br>";
echo "Body:<br>";
echo "$body";

}

}

?>

Thank you very much for any assistance you give, I am new to this email handling thing, any and all assistance will be GREATLY appreciated!

Thanks,
Brian

    Can't help you much if we don't know what the problem is. Post the error nos and messages please.

      Warning: imap_open(): Couldn't open stream brianbourdon.net:110 in /home/brianbo/public_html/stuff/mail.php on line 3

      Warning: imap_headers(): supplied argument is not a valid imap resource in /home/brianbo/public_html/stuff/mail.php on line 4
      You have no mail!

      Also note, i have tried serveral things besides the brianbourdon.net:110... i have tried mail.brianbourdon.net, localhost, localhost/pop3:110, localhost/pop3, loclhost:110.. pretty much everything

      I didnt bother with that error because it doesnt seem to me like its going to help you at all

        a year later

        i realize this is an old post but i ran across it digging for my own solutions.

        i got this code to work -- there were just some typos --
        and this worked but was a wacky workaround:
        for ($x = 1; $x < $count; $x ++) {
        $idx=($x-1);
        $num = $x;

        ...
        }

        *****************************************
        here is a working version:

        $username = "username@yourserver.com"; 
        $password = "yourpassword"; 
        
        $mbox = imap_open ("{yourserver.com/imap/notls:143}", "$username", "$password"); 
        
        
        $headers = imap_headers($mbox);
        $count = count($headers); 
        
        if($count == 0) { 
            echo "<b> You have no mail! </b>"; 
        } else { 
        
        for($i = 1; $i <= $count; $i ++) { 
        
        
         $headers = imap_headerinfo ($mbox,$i, 80, 80); 
        
        $subject= $headers->fetchsubject;
         $from = $headers->from;
         foreach ($from as $id => $object) {
        		$fromaddress = $object->mailbox . "@" . $object->host;
        	}
        
        $body = imap_body($mbox,$i); 
        
        echo "From:   $fromaddress<br>";
        echo "Subject: $subject<br>"; 
        echo "Body:<br>"; 
        echo "$body"; 
         echo "<br>&nbsp;<hr>&nbsp;<br>"; 
        
        } 
        
        } 
        imap_close($mbox);
        

          Sounds like imap_open is failing.

          You should check that you can connect to the imap server by connecting to it using a normal mail client (e.g. Thunderbird). Ideally, do so from your dev / production web app server (whichever one is causing the problem).

          If you can connect using a normal imap client from the same machine, to the same server / mailbox, but you can't in PHP, then more investigation will be required.

          Consult your mail server administrator to see if they can tell you why. Try running Ethereal on the server to watch the connection to see if you can determine why it failed from that.

          Mark

            Write a Reply...