Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts

    Get Email from POP

    All,
    I have the following script:
    PHP Code:
    <?php
    $fp 
    fsockopen('pop.secureserver.net'995$erno$estr10); // Connect 
    echo 'Open: '.fgets($fp128); 
    fwrite($fp"myemailaddress"128); // Enter username 
    echo '<br />User: '.fgets($fp128); 
    fwrite($fp"myemailpassword"128); // Enter password 
    echo '<br />Pass: '.fgets($fp128); 
    fwrite($fp"STAT\n"128); 
    echo 
    '<br />Stat: '.fgets($fp128); // Get some message information

    fwrite($fp"RETR 1\n"32); 

    $octets fgets($fp64); // read the first line 
    $parts explode(' '$octets); // split the first line by spaces 
    $octets $parts[1]; // we want the data after the second space 
    settype($octets'int'); // make sure its a number 

    $bytesread 0// we havent read any bytes of the actual email yet 
    $data 'Email Message Follows: <br /><br />'

    while(
    $bytesread $octets){ 

      
    $new_data fgets($fp4096); // read the data 
      
    $data .= '<br />'.$new_data// add it onto the existing data 
      
    $byteslength strlen($new_data); 
      
    $bytesread += $byteslength



    // The final line was just a dot (which is the ending byte string for SMTP messages (.\015\012) 
    // so i decided just to read that and get rid of it, so that my quit 
    // status message would appear properly 

    fread($fp64); 

    echo 
    $data


    fwrite($fp"QUIT\n"128); 
    echo 
    'Quit Status: '.fgets($fp128); 

    fclose($fp); 

    ?>
    However, when I run this I don't get any emails showing to the screen even though I know I have one unread one in there. Any ideas?

    Thanks in advance.

  • #2
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Let me tell you what I'm trying to do. I'm trying to run a script that will query a mailbox I designate. If there is new mail I want it to parse out the subject and if there is an attachment. I'd like to store the attachment in a folder on the webserver and then do some SQL. I'm using a shared environment so IMAP isn't installed because it's a security issue as I'm told. Any ideas on how I could do this? I think using the fsockopen is the only way to check this but I've never used this before so need some help with it.

    Thanks.

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Is there any other way to do this without using IMAP? So I can try and google those methods?

  • #4
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Ok so I found this snippet:
    PHP Code:
    <?php

    $fp
    =fsockopen("pop.secureserver.net"995$errno$errstr30);
    if(
    $fp){
        echo 
    'Connected!<br>';
        
        
    $username="USER email@email.com\r\n";
        
    $password="PASS password\r\n";

        
    $us=fwrite($fp$usernamestrlen($username));
        
    $ur=fgets($fp);
        if(!
    $ur){
        echo 
    "The username didn't send>";
        }
        echo 
    'Username sent, server response: '.$ur.'<br>';
        
    $ps=fwrite($fp$passwordstrlen($password));
        if(!
    $ps){
        echo 
    "The password didn't send<br>";
        }
        
    $pr=fgets($fp);
        echo 
    'Password sent, server response: '.$pr.'<br>';
        
        
    $res=fgets($fp);
        
    $parts=explode(" "$res);
        echo 
    $parts[4].' messages on server<br><br>';
        
        
    $cmd="LIST\r\n";
        
    $get=fwrite($fp$cmdstrlen($cmd));
        
    $msg=fread($fp8192);
        echo 
    '<pre>'.$msg.'</pre>';
        
        
    $cmd="RETR 1\r\n";
        
    $get=fwrite($fp$cmdstrlen($cmd));
        
    $msg=fread($fp8192);  //This is only retrieving the first line it seems.  The server 'should' have sent an entire message worth of data.
        
    echo '<pre>'.$msg.'</pre>';
    }
    else{
        echo 
    'Failed Connecting!<br>';
    }
    fclose($fp);
    ?>
    However, it won't send the username and password to the server. Any ideas?

    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •