Jump to content

fgtsai0418

Members
  • Posts

    26
  • Joined

  • Last visited

fgtsai0418's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. If I have message on screen. How to fetch that and put into mysql ?
  2. Hi I want use imap_search to sort what I want , but it not working. can somebody help? <? set_time_limit(0); //Your gmail email address and password $username = 'name@gmail.com'; $password = 'pwd'; //Which folders or label do you want to access? - Example: INBOX, All Mail, Trash, labelname //Note: It is case sensitive $imapmainbox = "INBOX"; //Select messagestatus as ALL or UNSEEN which is the unread email $messagestatus = "UNSEEN"; //------------------------------------------------------------------- //Gmail Connection String $imapaddress = "{imap.gmail.com:993/imap/ssl}"; //Gmail host with folder $hostname = $imapaddress . $imapmainbox; //Open the connection $connection = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); //Grab all the emails inside the inbox //$emails = imap_search($connection,$messagestatus); $emails = imap_search($connection,$messagestatus,'FROM, "c12.mobile.net"' ); //number of emails in the inbox $totalemails = imap_num_msg($connection); echo "Total Emails: " . $totalemails . "<br>"; if($emails) { //sort emails by newest first rsort($emails); //loop through every email int he inbox foreach($emails as $email_number) { //grab the overview and message $header = imap_fetch_overview($connection,$email_number,0); //Because attachments can be problematic this logic will default to skipping the attachments $message = imap_fetchbody($connection,$email_number,1.1); if ($message == "") { // no attachments is the usual cause of this $message = imap_fetchbody($connection, $email_number, 1); } //split the header array into variables $status = ($header[0]->seen ? 'read' : 'unread'); $subject = $header[0]->subject; $from = $header[0]->from; $date = $header[0]->date; echo "status: " . $status . "<br>"; echo "from: " . $from . "<br>"; echo "date: " . $date . "<br>"; echo "message: " . $message . "<br><hr><br>"; } } // close the connection imap_close($connection); ?>
  3. This code can fetch Gmail all mail. But how to retrieve particular "domain name" like @123.xstartwar.com or particular "message" which title have "Mobile Position Report" <? set_time_limit(0); //Your gmail email address and password $username = 'name@gmail.com'; $password = 'pwd'; //Which folders or label do you want to access? - Example: INBOX, All Mail, Trash, labelname //Note: It is case sensitive $imapmainbox = "INBOX"; //Select messagestatus as ALL or UNSEEN which is the unread email $messagestatus = "UNSEEN"; //------------------------------------------------------------------- //Gmail Connection String $imapaddress = "{imap.gmail.com:993/imap/ssl}"; //Gmail host with folder $hostname = $imapaddress . $imapmainbox; //Open the connection $connection = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); //Grab all the emails inside the inbox $emails = imap_search($connection,$messagestatus); //number of emails in the inbox $totalemails = imap_num_msg($connection); echo "Total Emails: " . $totalemails . "<br>"; if($emails) { //sort emails by newest first rsort($emails); //loop through every email int he inbox foreach($emails as $email_number) { //grab the overview and message $header = imap_fetch_overview($connection,$email_number,0); //Because attachments can be problematic this logic will default to skipping the attachments $message = imap_fetchbody($connection,$email_number,1.1); if ($message == "") { // no attachments is the usual cause of this $message = imap_fetchbody($connection, $email_number, 1); } //split the header array into variables $status = ($header[0]->seen ? 'read' : 'unread'); $subject = $header[0]->subject; $from = $header[0]->from; $date = $header[0]->date; echo "status: " . $status . "<br>"; echo "from: " . $from . "<br>"; echo "date: " . $date . "<br>"; echo "message: " . $message . "<br><hr><br>"; //This is where you would want to start parsing your emails, send parts of the email into a database or trigger something fun to happen based on the emails. } } // close the connection imap_close($connection); ?>
  4. I use imap function to open my Gmail It works, but information is wrong. Because my gmail have 108 mails. But it only show "0" =================================== Date: Fri, 2 Aug 2013 10:09:52 +0800Driver: pop3Mailbox: {gmail-pop.l.google.com:995/pop3/notls/ssl/novalidate-cert/user="name@gmail.com"}INBOXMessages: 0Unread: 0Size: 0 ================================= <?php $authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}"; $user="name@gmail.com"; $pass="pwd"; $mbox=imap_open( $authhost, $user, $pass ); { $check = imap_mailboxmsginfo($mbox); echo "Date: " . $check->Date . "<br />n" ; echo "Driver: " . $check->Driver . "<br />n" ; echo "Mailbox: " . $check->Mailbox . "<br />n" ; echo "Messages: " . $check->Nmsgs . "<br />n" ; echo "Unread: " . $check->Unread . "<br />n" ; echo "Size: " . $check->Size . "<br />n" ; imap_close($mbox); } ?>
  5. Hi Moderator How can I fix it, if I have10 mails or 100 mails? How to setup, only unread mail?
  6. Thank You, Foxy. New problem on line 26 Fatal error: Maximum execution time of 30 seconds exceeded in C:AppServwwwg.php <? $authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}"; $user="name@gmail.com"; $pass="pwd"; $mbox=imap_open( $authhost, $user, $pass ); /* grab emails */ $emails = imap_search($mbox , "ALL"); /* if emails are returned, cycle through each... */ if($emails) { /* begin output var */ $output = ''; /* put the newest emails on top */ rsort($emails); /* for every email... */ foreach($emails as $email_number) { /* get information specific to this email */ $overview = imap_fetch_overview($mbox,$email_number,0); $message = imap_fetchbody($mbox,$email_number,2); /* output the email header information */ $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; $output.= '<span class="from">'.$overview[0]->from.'</span>'; $output.= '<span class="date">on '.$overview[0]->date.'</span>'; $output.= '</div>'; /* output the email body */ $output.= '<div class="body">'.$message.'</div>'; } echo $output; } /* close the connection */ imap_close($mbox); ?>
  7. Parse error: syntax error, unexpected T_VARIABLE in C:AppServwwwg.php on line 21
  8. somebody help check what's wrong is it? <? $authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}"; $user="name@gmail.com"; $pass="pwd"; $mbox=imap_open( $authhost, $user, $pass ) /* grab emails */ $emails = imap_search($mbox , "ALL"); /* if emails are returned, cycle through each... */ if($emails) { /* begin output var */ $output = ''; /* put the newest emails on top */ rsort($emails); /* for every email... */ foreach($emails as $email_number) { /* get information specific to this email */ $overview = imap_fetch_overview($mbox,$email_number,0); $message = imap_fetchbody($mbox,$email_number,2); /* output the email header information */ $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; $output.= '<span class="from">'.$overview[0]->from.'</span>'; $output.= '<span class="date">on '.$overview[0]->date.'</span>'; $output.= '</div>'; /* output the email body */ $output.= '<div class="body">'.$message.'</div>'; } echo $output; } /* close the connection */ imap_close($mbox); ?>
  9. So...Use imap_check, imap_headerinfo, imap_body will get message body?? How to get all mail ? not only unread mail ?
  10. Now I can do is it connect to Gmail but I don't know how to fetch a message only for "@123mobile.com" this domain name. ***************************** <?php $authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}"; $user="username@gmail.com"; $user="name@gmail.com"; $pass="pwd"; if ($mbox=imap_open( $authhost, $user, $pass )) { echo "<h1>Connected</h1>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 { echo "<h1>FAIL!</h1>n"; } ?>
×
×
  • Create New...