Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-12-2009, 09:54 PM   PM User | #1
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
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.
treeleaf20 is offline   Reply With Quote
Old 10-12-2009, 10:40 PM   PM User | #2
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
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.
treeleaf20 is offline   Reply With Quote
Old 10-13-2009, 02:29 PM   PM User | #3
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
Is there any other way to do this without using IMAP? So I can try and google those methods?
treeleaf20 is offline   Reply With Quote
Old 10-13-2009, 02:53 PM   PM User | #4
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
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.
treeleaf20 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:25 AM.


Advertisement
Log in to turn off these ads.