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 8 of 8
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    Unhappy read gmail or emails in my php pages

    hi

    i am stuck again

    on one of my admin pages i want to be able to read my emails from my email account (gmail can change the email provider if you wish).
    i have done some research and found out about imap.
    i have tryed a few script off the internet but i get error from them or don't undstand how to put them together or they are unstable eg somtimes they fecth the emails and other times they don't.
    can any one give me a link to a good script or be able to tell me how to do this(script wise or in simple terms)

    thanks alot you being a massive help

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Here you go, reads pop3 accounts.

    PHP Code:
    <?php

    require("email_functions.php");

    global 
    $timeout$error$buffer;

    // Date in the past
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    // always modified
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");

    // HTTP/1.1
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0"false);

    // HTTP/1.0
    header("Pragma: no-cache");

    ob_start();

    //-----------------------------------------------------------------------------
    //                 Declarations
    //-----------------------------------------------------------------------------

    $error            "";                                                        //    Error string.

    $timeout          90;                                                        //    Default timeout before giving
    up on a network operation.

    $Count            = -1;                                                        //    Mailbox msg count

    $buffer           512;                                                       //    Socket buffer for socket
    fgets() callsmax per RFC 1939 the returned line a POP3
                                                                                
    //    server can send is 512 bytes.

    $server               "mail.yourdomain.com";                //    Set this to hard code
    the server name

    $RFC1939          
    true;                                                    //    Set by noop(). See
    rfc1939.txt

    $msg_list_array 
    = array();                                                  //    List of messages from server

    $login                 'email_login';
    $pass                  'email_password';
    $KeyUserID            'me';                                                      //        for the db record to id the program
    as the user

    //-----------------------------------------------------------------------------
    //                 Control Code
    //-----------------------------------------------------------------------------
       //echo "<h2>Starting Program</h2><br>";
            
    set_time_limit($timeout);

            
    $fp connect ($server$port 110);

        
    $Count login($login,$pass$fp);

        if( (!
    $Count) or ($Count == -1) )
        {
            
    do_log("TIRS""Check for new messages",''"No Messages");
            exit;
        }
    // end if

        // ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT!
        // register_shutdown_function(quit());

        
    if ($Count 1)
        {
            die();
        } else {
            
    //echo "Login OK: Inbox contains [$Count] messages<BR>\n";
            
    do_log("TIRS""Check for new messages",''"$Count Messages");
            
    $msg_list_array uidl(""$fp);
            
    set_time_limit($timeout);
        }
    // end if

        // loop thru the array to get each message
        
    for ($i=1$i <= $Count$i++){
                
    set_time_limit($timeout);
                
    $MsgOne get($i$fp);

                if( (!
    $MsgOne) or (gettype($MsgOne) != "array") )
                {
                    
    //echo "oops, Message not returned by the server.<BR>\n";
                    
    exit;
                }
    // end if
                /*
                    call the function to read the message
                    returns true if access, breakdown and insertion
                    in to db are completed sucessfully
               */
                  
    message_details($MsgOne$i$fp);

          }
    // end for loop

          //close the email box and delete all messages marked for deletion
          
    quit($fp);

        
    //close the application
        //echo "<br>Finished</b>";
        
    exit;

    //-----------------------------------------------------------------------------
    //                                    Function Listing
    //-----------------------------------------------------------------------------

    //-----------------------------------------------------------------------------
    //                                    Get the Message Details
    //-----------------------------------------------------------------------------
    function     message_details($MsgOne$msgNo$fp)
            {
            
    /*
            Function to read the message and extract :
                a. subject
                b. date
                c. split the body line by line
       */
                
    $body                     '';                    // get the body of the message into 1 variable
                
    $subjects             '';         // get the subject of the email
                
    $dates                     '';                    // get the date of the email
               
    $body_start_key false;          // body starts at blank line, blank line is
    separator for from headers to body
               $TIRSFlag             
    false;      // flag for seeing if the email is really to
    be processed by the app
               $base64Flag     
    false;      // flag to handle base 64 encoding by
    email systems.



                foreach (
    $MsgOne as $key => $value)
            {
            if (
    trim($value) == "Content-Transfer-Encoding: base64"){
              
    $base64Flag true;
            }
    //end if

            //get the subject line of the email
            
    if (strlen(stristr($value"Subject"))>1){
              
    $subjects trim(stristr($value" "));

              
    //look for IncidentNo in the subject to see if we need to attempt to process the email
              
    if (strlen(stristr($subjects"IncidentNo:"))>1){
                  
    $TIRSFlag true;
                }
    // end if
            
    }// end if

            //get the date of the email
            
    if (strlen(stristr($value"Date"))>1){
              
    $dates trim(stristr($value" "));
                
    $date_key $key;
            }
    // end if


            //the body
            
    if (strlen(trim($value))==0){
              if (
    $body_start_key == false){ $body_start_key true; } //set the start key for the body
            
    }//end if

            
    if ($body_start_key == true){
              
    $body .= trim($value);
              if (
    $base64Flag == false){ $body .="<br />"; }
            }
    // end if

          
    }// end foreach

          // only create incident if the subject line contains the word incident
          
    if ($TIRSFlag == false){

              
    //delete the message
              
    delete($msgNo$fp);

          }else{

              
    //decode the message if its base64 encoded
              
    if ($base64Flag == true) {
                
    $body base64_decode($body);
              }
    //end if

              // call the function that does the sql inserts
              
    create_incident($subjects$body$msgNo$fp);

          }
    // end if
            
    }// end function

    //-----------------------------------------------------------------------------
    //                                    Create the incident
    //-----------------------------------------------------------------------------
    function create_incident($subject$message_body$msgNo$fp)
            {
                 
    //process the body of the email and take it apart and find stuff in it...do whatever processing you need to here
                 //the code below is simply a hint and probably not relevant to your situation
                 //its strictly here as a guide as to what can be done with the body of the email
                 //my application takes the subject and body apart and creates a record in our web-based
                 //application's database (the code for this has been removed...)


                 // declarations for function
                    
    $inc_sec_off '';
                    
    $inc_site    '';
                    
    $inc_type    '';
                    
    $inc_issue   '';
                    
    $inc_co_id   '';
                    
    $inc_http    '';
                  
    $options     '';

                  
    // take the subject apart to get the individual elements

               
    $sub_details         stristr($subject":");                                       // get
    rest of subject line from the first ':'
               
    $split_subject     explode (" "$sub_details);                                  //
    split on space
               $incident_no            
    =    trim($split_subject[1]);                                      //
    incident number from email
               $incident_type        
    trim($split_subject[3]);                                      //
    incident type from email
               $inc_date                 
    trim($split_subject[5]);                                                        // incident date
    from email
                 $inc_dates                
    explode("/",$inc_date);


                 if (
    count($inc_dates)>1){
                         
    $inc_date            $inc_dates[2]."-".$inc_dates[0]."-".$inc_dates[1];
        
    //proper date format (Damned Americans)
                 
    }//end if

                 
    $weekday                    date"l"$inc_date);                                                            // get the weekday

                 
    $time                         strtotime($inc_date " "trim($split_subject[6]));

                 
    $inc_time                 date("H:i:s"strftime($time) );                                        // incident
    time from email

                 
    //convert the body crlf to <br> tags if not done when the message was built
                 
    if (strlen(stristr($message_body,"<br>"))==0){
                         
    $message_body nl2br($message_body);
               }

               
    // take the body apart to get the individual elements
               
    $body                        =    explode("<br />"$message_body);

               for (
    $x=0$x<count($body); $x++){

                       if (
    strlen(stristr($body[$x], "Security Officer"))>1)       { 
    $inc_sec_off            substr(stristr($body[$x], ":"),1);   }
                       if (
    strlen(stristr($body[$x], "client_number"))>1)                {  $inc_site 
                
    substr(stristr($body[$x], ":"),1);   }
                       if (
    strlen(stristr($body[$x], "Company ID"))>1)                      {  $inc_co_id 
                
    substr(stristr($body[$x], ":"),1);   }
                       if (
    strlen(stristr($body[$x], "Are"))>1)                            {  $inc_issue
                
    substr(stristr($body[$x], ":"),1);   }
                       if (
    strlen(stristr($body[$x], "http"))>1)                           {  $inc_https
                
    explode("//",$body[$x]);                 }

           }
    // end for loop

           //echo $message_body;


          //delete the email if the insertion was succesful
              
    if ($result && $result1){
                
    delete ($msgNo$fp);
              }
    // end if


            
    }// end function


    ?>
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    email_functions.php
    PHP Code:
    <?php
    /*
    <!-- Version=2.30 Date=11/05/04 Name=email_functions.php --> */

    function connect ($server$port)
        {
            global 
    $buffer;
            
    //    Opens a socket to the specified server. Unless overridden,
            //    port defaults to 110. Returns true on success, false on fail

            // If MAILSERVER is set, override $server with it's value
            
    $e_server $server;

            if(!
    $fp fsockopen($e_server$port, &$errno, &$errstr))
            {
                
    $error "POP3 connect: Error [$errno] [$errstr]";
                return 
    false;
            }

            
    stream_set_blocking($fp,true);
            
    update_timer();
            
    $reply fgets($fp,$buffer);
            
    $reply strip_clf($reply);
            if(!
    is_ok($reply))
            {
                
    $error "POP3 connect: Error [$reply]";
                return 
    false;
            }

            
    $BANNER parse_banner($reply);
            
    $RFC1939 noop($fp);
            if(
    $RFC1939)
            {
                
    $error "POP3: premature NOOP OK, NOT an RFC 1939 Compliant server";
                
    quit($fp);
                return 
    false;
            }
            return 
    $fp;
        }
    // end function

    function noop ($fp)
        {

            
    $cmd "NOOP";
            
    $reply send_cmd($cmd$fp);
            if(!
    is_ok($reply))
            {
                return 
    false;
            }
            return 
    true;
        }
    // end function

    function user ($user$fp)
        {
            
    // Sends the USER command, returns true or false

            
    if(empty($user))
            {
                
    $error "POP3 user: no user id submitted";
                return 
    false;
            }

            
    $reply send_cmd("USER $user"$fp);
            if(!
    is_ok($reply))
            {
                
    $error "POP3 user: Error [$reply]";
                return 
    false;
            }
            return 
    true;
        }
    // end function

    function pass ($pass$fp)
        {
            
    // Sends the PASS command, returns # of msgs in mailbox,
            // returns false (undef) on Auth failure

            
    if(empty($pass))
            {
                
    $error "POP3 pass: no password submitted";
                return 
    false;
            }

            
    $reply send_cmd("PASS $pass"$fp);
            if(!
    is_ok($reply))
            {
                
    $error "POP3 pass: authentication failed [$reply]";
                
    quit($fp);
                return 
    false;
            }
            
    //    Auth successful.
            //echo "<br>User Authenticated<br>";
            
    $count last("count"$fp);
            
    $COUNT $count;
            
    $RFC1939 noop($fp);
            if(!
    $RFC1939)
            {
                
    $error "POP3 pass: NOOP failed. Server not RFC 1939 compliant";
                
    quit($fp);
                return 
    false;
            }
            return 
    $count;
        }
    // end function

    function login ($login ""$pass ""$fp)
        {
            
    // Sends both user and pass. Returns # of msgs in mailbox or
            // false on failure (or -1, if the error occurs while getting
            // the number of messages.)

            
    if(!user($login$fp))
            {
                
    //    Preserve the error generated by user()
                
    return false;
            }

            
    $count pass($pass$fp);
            if( (!
    $count) or ($count == -1) )
            {
                
    //    Preserve the error generated by last() and pass()
                
    return "-1";
            }
            return 
    $count;
        }
    // end function

    function top ($msgNum$numLines "0"$fp)
        {
            
    //    Gets the header and first $numLines of the msg body
            //    returns data in an array with each returned line being
            //    an array element. If $numLines is empty, returns
            //    only the header information, and none of the body.


            
    update_timer();


            
    $buffer $buffer;
            
    $cmd "TOP $msgNum $numLines";
            
    fwrite($fp"TOP $msgNum $numLines\r\n");
            
    $reply fgets($fp$buffer);
            
    $reply $strip_clf($reply);
            if(
    $DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
            if(!
    is_ok($reply))
            {
                
    $error "POP3 top: Error [$reply]";
                return 
    false;
            }

            
    $count 0;
            
    $MsgArray = array();

            
    $line fgets($fp,$buffer);
            while ( !
    ereg("^\.\r\n",$line))
            {
                
    $MsgArray[$count] = $line;
                
    $count++;
                
    $line fgets($fp,$buffer);
                if(empty(
    $line))    { break; }
            }

            return 
    $MsgArray;
        }
    // end function

    function pop_list ($msgNum ""$fp)
        {
            
    //    If called with an argument, returns that msgs' size in octets
            //    No argument returns an associative array of undeleted
            //    msg numbers and their sizes in octets
                    
    global $buffer;

            
    $Total $Count;
            if( (!
    $Total) or ($Total == -1) )
            {
                return 
    false;
            }
            if(
    $Total == 0)
            {
                return array(
    "0","0");
                
    // return -1;    // mailbox empty
            
    }

            
    $update_timer();

            if(!empty(
    $msgNum))
            {
                
    $cmd "LIST $msgNum";
                
    fwrite($fp,"$cmd\r\n");
                
    $reply fgets($fp,$buffer);
                
    $reply $strip_clf($reply);
                if(!
    is_ok($reply))
                {
                    
    $error "POP3 pop_list: Error [$reply]";
                    return 
    false;
                }
                list(
    $junk,$num,$size) = explode(" ",$reply);
                return 
    $size;
            }
            
    $cmd "LIST";
            
    $reply $send_cmd($cmd$fp);
            if(!
    is_ok($reply))
            {
                
    $reply $strip_clf($reply);
                
    $error "POP3 pop_list: Error [$reply]";
                return 
    false;
            }
            
    $MsgArray = array();
            
    $MsgArray[0] = $Total;
            for(
    $msgC=1;$msgC <= $Total$msgC++)
            {
                if(
    $msgC $Total) { break; }
                
    $line fgets($fp,$buffer);
                
    $line $strip_clf($line);
                if(
    ereg("^\.",$line))
                {
                    
    $error "POP3 pop_list: Premature end of list";
                    return 
    false;
                }
                list(
    $thisMsg,$msgSize) = explode(" ",$line);
                
    settype($thisMsg,"integer");
                if(
    $thisMsg != $msgC)
                {
                    
    $MsgArray[$msgC] = "deleted";
                }
                else
                {
                    
    $MsgArray[$msgC] = $msgSize;
                }
            }
            return 
    $MsgArray;
        }
    // end function

    function get ($msgNum$fp)
        {
            
    //    Retrieve the specified msg number. Returns an array
            //    where each line of the msg is an array element.

            
    global $buffer;
            
    update_timer();

            
    $buffer $buffer;
            
    $cmd "RETR $msgNum";

            
    $reply send_cmd($cmd$fp);

            if(!
    is_ok($reply))
            {
                
    $error "POP3 get: Error [$reply]";
                return 
    false;
            }

            
    $count 0;
            
    $MsgArray = array();

            
    $line fgets($fp,$buffer);
            while ( !
    ereg("^\.\r\n",$line))
            {
                
    $MsgArray[$count] = $line;
                
    $count++;
                
    $line fgets($fp,$buffer);
                if(empty(
    $line))    { break; }
            }
            return 
    $MsgArray;
        }
    // end function

    function last $type "count"$fp )
        {
            
    //    Returns the highest msg number in the mailbox.
            //    returns -1 on error, 0+ on success, if type != count
            //    results in a popstat() call (2 element array returned)

            
    $last = -1;

            
    $reply send_cmd("STAT"$fp);
            if(!
    is_ok($reply))
            {
                
    $error "POP3 last: error [$reply]";
                return 
    $last;
            }

            
    $Vars explode(" ",$reply);
            
    $count $Vars[1];
            
    $size $Vars[2];
            
    settype($count,"integer");
            
    settype($size,"integer");
            if(
    $type != "count")
            {

                return array(
    $count,$size);
            }
            return 
    $count;
        }
    // end function

    function resets($fp)
        {
            
    //    Resets the status of the remote server. This includes
            //    resetting the status of ALL msgs to not be deleted.
            //    This method automatically closes the connection to the server.


            
    $reply $send_cmd("RSET"$fp);
            if(!
    is_ok($reply))
            {
                
    //    The POP3 RSET command -never- gives a -ERR
                //    response - if it ever does, something truely
                //    wild is going on.

                
    $error "POP3 reset: Error [$reply]";
            }
            
    quit($fp);
            return 
    true;
        }
    // end function

    function send_cmd $cmd$fp )
        {
            
    //    Sends a user defined command string to the
            //    POP server and returns the results. Useful for
            //    non-compliant or custom POP servers.
            //    Do NOT include the \r\n as part of your command
            //    string - it will be appended automatically.

            //    The return value is a standard fgets() call, which
            //    will read up to $buffer bytes of data, until it
            //    encounters a new line, or EOF, whichever happens first.

            //    This method works best if $cmd responds with only
            //    one line of data.
                    
    global $buffer;
            if(!isset(
    $fp))
            {
                
    $error "POP3 send_cmd: No connection to server";
                return 
    false;
            }

            if(empty(
    $cmd))
            {
                
    $error "POP3 send_cmd: Empty command string";
                return 
    "";
            }

            
    $buffer $buffer;
            
    update_timer();
            
    fwrite($fp,"$cmd\r\n");
            
    $reply fgets($fp,$buffer);
            
    $reply strip_clf($reply);
            return 
    $reply;
        }
    // end function

    function quit($fp)
        {
            
    //    Closes the connection to the POP3 server, deleting
            //    any msgs marked as deleted.
            
    global $buffer;

            
    $cmd "QUIT";
            
    fwrite($fp,"$cmd\r\n");
            
    $reply fgets($fp,$buffer);
            
    $reply strip_clf($reply);
            
    fclose($fp);
            return 
    true;
        }
    // end function


    function is_ok ($cmd "")
        {
            
    //    Return true or false on +OK or -ERR

            
    if(empty($cmd))                 { return false; }
            if ( 
    ereg ("^\+OK"$cmd ) )    { return true; }
            return 
    false;
        }
    // end function

    function strip_clf ($text "")
        {
            
    // Strips \r\n from server responses

            
    if(empty($text)) { return $text; }
            
    $stripped ereg_replace("\r","",$text);
            
    $stripped ereg_replace("\n","",$stripped);
            return 
    $stripped;
        }
    // end function

    function parse_banner $server_text )
        {
            
    $outside true;
            
    $banner "";
            
    $length strlen($server_text);
            for(
    $count =0$count $length$count++)
            {
                
    $digit substr($server_text,$count,1);
                if(!empty(
    $digit))
                {
                    if( (!
    $outside) and ($digit != '<') and ($digit != '>') )
                    {
                        
    $banner .= $digit;
                    }
                    if (
    $digit == '<')
                    {
                        
    $outside false;
                    }
                    if(
    $digit == '>')
                    {
                        
    $outside true;
                    }
                }
            }
            
    $banner strip_clf($banner);    // Just in case
            
    return "<$banner>";
        }
    // end function

    function popstat ()
        {
            
    //    Returns an array of 2 elements. The number of undeleted
            //    msgs in the mailbox, and the size of the mbox in octets.

            
    $PopArray last("array");

            if(
    $PopArray == -1) { return false; }

            if( (!
    $PopArray) or (empty($PopArray)) )
            {
                return 
    false;
            }
            return 
    $PopArray;
        }
    // end function

    function uidl ($msgNum ""$fp)
        {
            
    //    Returns the UIDL of the msg specified. If called with
            //    no arguments, returns an associative array where each
            //    undeleted msg num is a key, and the msg's uidl is the element
            //    Array element 0 will contain the total number of msgs

            
    global $buffer$Count;

            if(!empty(
    $msgNum))
            {
                
    $cmd "UIDL $msgNum";
                
    $reply send_cmd($cmd);
                if(!
    is_ok($reply))
                {
                    
    $error "POP3 uidl: Error [$reply]";
                    return 
    false;
                }
                list (
    $ok,$num,$myUidl) = explode(" ",$reply);
                return 
    $myUidl;
            }
            else
            {
                
    //update_timer();

                
    $UIDLArray = array();
                
    $Total $Count;
                
    $UIDLArray[0] = $Total;

                if (
    $Total 1)
                {
                    return 
    $UIDLArray;
                }
                
    $cmd "UIDL";
                
    fwrite($fp"UIDL\r\n");
                
    $reply fgets($fp$buffer);
                
    $reply strip_clf($reply);

                if(!
    is_ok($reply))
                {
                    
    $error "POP3 uidl: Error [$reply]";
                    return 
    false;
                }

                
    $line "";
                
    $count 1;
                
    $line fgets($fp,$buffer);
                while ( !
    ereg("^\.\r\n",$line))
                {
                    if(
    ereg("^\.\r\n",$line))
                    {
                        break;
                    }
                    list (
    $msg,$msgUidl) = explode(" ",$line);
                    
    $msgUidl strip_clf($msgUidl);
                    if(
    $count == $msg)
                    {
                        
    $UIDLArray[$msg] = $msgUidl;
                    }
                    else
                    {
                        
    $UIDLArray[$count] = "deleted";
                    }
                    
    $count++;
                    
    $line fgets($fp,$buffer);
                }
            }
            return 
    $UIDLArray;
        }
    // end function

    function delete ($msgNum ""$fp)
        {
            
    //    Flags a specified msg as deleted. The msg will not
            //    be deleted until a quit() method is called.

            
    if(empty($msgNum))
            {
                
    $error "POP3 delete: No msg number submitted";
                return 
    false;
            }
            
    $reply send_cmd("DELE $msgNum"$fp);
            if(!
    is_ok($reply))
            {
                
    $error "POP3 delete: Command failed [$reply]";
                return 
    false;
            }
            return 
    true;
        }
    // end function

    function conn($sql$db_account='')
            {

        
    /*

            add code to decide what server/db to tag when inserting the data

            include("../includes/portal.php");

        */

            
    $host  $db_account['host'];
            
    $user  $db_account['login'];
            
    $pass  $db_account['pwd'];
            
    $db    $db_account['db'];

                
    //echo "commnecing connection to local db<br>";
                //echo "mysql_connect($host, $user, $pass)";

                
    ob_flush();
                
    //$conn = mysql_connect($host, $user, $pass) or die("Can't connect because ". mysql_error());
                
    if (!($conn=mysql_connect($host$user$pass)))  {
                    
    printf("error connecting to DB by user = $user and pwd=$pass");
                    exit;
                }

                
    $db3 mysql_select_db($db$conn);// or die("Unable to connect to local database");

                
    $result mysql_query($sql);// or die ("Can't connect because ".
    mysql_error()."<br>$sql");

                return 
    $result;

            }
    //end function


    function update_timer()
        {
         global 
    $timeout;
         
    set_time_limit($timeout);

        }
    ?>
    logging.php
    PHP Code:
    <?
    //<!-- Version=2.30 Date=11/08/04 Name=logging.php -->
    /*

    -----------------------------------------------------------------------------

        goes to db 
        if db not available, goes to text file
    */

    function do_log($client$activity$sql=''$success)
            {
            
    //logs the client, activity, sql and success or failure of the action
            //
            /*
            $host = "192.168.100.10";
            $user = "root";
            $pass = "3JN4xM9Jvgj2VwHe";
             
            */
            
    $host  '192.168.160.31';   
            
    $user  'rume';
            
    $pass  'RumE2#$w';
            
    $db     "loggingdb";
             
            
    $err 0;
                
    //echo "commnecing connection to local db<br>";
                 
                
    if (!($conn=mysql_connect($host$user$pass)))  {
                    
    $err mysql_errno();
                }
                if (!
    $db3=mysql_select_db($db$conn)){ //or die("Unable to connect to local database");
                    
    $err mysql_errno();
                }
                 
                if (
    $err != 0){
                 
                  
    //database is not available or can't be connected to at the moment
                  
    write_log($client$activity$sql$success);
                 
                }else{
                   
    $time time();
                  
    //enter the data into the log table   
                  
    $sql "insert into logg (client, sql, activity, success, unix_timestamp) values ('$client','$sql','$activity','$success',$time)"
                   
    //echo $sql;
                  
    $result mysql_query($sql) or die ("Can't connect because "mysql_error()."<br>$sql");
                  
    $err mysql_errno();
            
    //if ($err != 0){
                
    write_log($client$activity$sql$success);     
            
    //}// end if
         
          
    }// end if
                 
            
    }//end function     
             
             
    function write_log($client$activity$sql$success)
            {
                
    //write the text log
                
    $time time();
                
    $filename "C:\\apisonline.com\\html\\scripts\\logs\\test.log";
                 
                
    $somecontent "Client\t$client.\nActivity\t$activity\nSQL\t:$sql\nSuccess:\t$success($time)\n\n";
                     
                    
    // Let's make sure the file exists and is writable first.
                    
    if (is_writable($filename)) {
                     
                       if (!
    $handle fopen($filename'a')) {
                             
    //echo "Cannot open file ($filename)";
                             //exit;
                       
    }
                     
                       
    // Write $somecontent to our opened file.
                       
    if (fwrite($handle$somecontent) === FALSE) {
                           
    //echo "Cannot write to file ($filename)";
                           //exit;
                       
    }
                       
                       
    //echo "Success, wrote ($somecontent) to file ($filename)";
                       
                        
    fclose($handle);
         
                }
    // end if         
             
            
    }// end function

    ?>
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    Unhappy really sorry

    hi

    i have used your code and am getting errors onece i fix on error i get another and i think it is just me is there any chance you can put the code to gether in a file and send it to me
    as when i do it i get
    Parse error: parse error in C:\wamp\www\mywigan\admin\email\index1.php on line 34
    then another error and so on
    i am really sorry and big thanks if you can do this for me thanks again

    i feel like and idiot i get the code handed to me on a plate and i still can't do/ it i am so sorry.

    well hopfull it will be sorted soon thanks agin

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    You have to customize it. Meaning put your email account details in it, and paths, etc.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #6
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Quote Originally Posted by phpcodelearner View Post
    hi

    i have used your code and am getting errors onece i fix on error i get another and i think it is just me is there any chance you can put the code to gether in a file and send it to me
    as when i do it i get
    Parse error: parse error in C:\wamp\www\mywigan\admin\email\index1.php on line 34
    then another error and so on
    i am really sorry and big thanks if you can do this for me thanks again

    i feel like and idiot i get the code handed to me on a plate and i still can't do/ it i am so sorry.

    well hopfull it will be sorted soon thanks agin
    SOLVED i have done it hip hip hurray

    i did this

    PHP Code:
    <?php /* Created on: 11/3/2008 By Ron Hickey 6tx.net/gmail_mod 
    Gmail mod for admin panels or you can edit it and convert html results to XML for personal RSS reader */ 

    // enter gmail username below e.g.--> $m_username = "yourusername";
    $m_username "loginid";

    // enter gmail password below e.g.--> $m_password = "yourpword";
    $m_password "password";

    // enter the number of unread messages you want to display from mailbox or 
    //enter 0 to display all unread messages e.g.--> $m_acs = 0; 
    $m_acs 15

    // How far back in time do you want to search for unread messages - one month = 0 , two weeks = 1, one week = 2, three days = 3,
    // one day = 4, six hours = 5 or one hour = 6 e.g.--> $m_t = 6;
    $m_t 0;

    //----------->Nothing More to edit below
    //open mailbox..........please
    $m_mail imap_open ("{imap.gmail.com:993/imap/ssl}INBOX"$m_username "@gmail.com"$m_password)


    // or throw a freakin error............you pig
    or die("ERROR: " imap_last_error());

    // unix time gone by or is it bye.....its certanly not bi.......or is it? ......I dunno fooker 
    $m_gunixtp = array(2592000120960060480025920086400216003600);

    // Date to start search
    $m_gdmy date('d-M-Y'time() - $m_gunixtp[$m_t]); 

    //search mailbox for unread messages since $m_t date 
    $m_search=imap_search ($m_mail'UNSEEN SINCE ' $m_gdmy '');

    //If mailbox is empty......Display "No New Messages", else........ You got mail....oh joy
    if($m_search 1){ 
    $m_empty "No New Messages";} 
    else {

    // Order results starting from newest message
    rsort($m_search);

    //if m_acs > 0 then limit results
    if($m_acs 0){ 
    array_splice($m_search$m_acs);


    //loop it 
    foreach ($m_search as $what_ever) { 

    //get imap header info for obj thang 
    $obj_thang imap_headerinfo($m_mail$what_ever);
    $message imap_fetchbody($m_mail,$what_ever,2);


    //Then spit it out below.........if you dont swallow 
    echo "<body bgcolor=D3D3D3><div align=center><br /><font face=Arial size=2 color=#800000>Message ID# " $what_ever "</font>

    <table bgcolor=#D3D3D3 width=700 border=1 bordercolor=#000000 cellpadding=0 cellspacing=0>
    <tr>
    <td><table width=100% border=0>
    <tr>
    <td><table width=100% border=0>
    <tr>
    <td bgcolor=#F8F8FF><font face=Arial size=2 color=#800000>Date:</font> <font face=Arial size=2 color=#000000>" 
    date("F j, Y, g:i a"$obj_thang->udate) . "</font></td>
    <td bgcolor=#F8F8FF><font face=Arial size=2 color=#800000>From:</font> <font face=Arial size=2 color=#000000>" 
    $obj_thang->fromaddress "</font></td>
    <td bgcolor=#F8F8FF><font face=Arial size=2 color=#800000>To:</font> <font face=Arial size=2 color=#000000>" 
    $obj_thang->toaddress " </font></td>
    </tr>
    <tr>
    </table>
    </td>
    </tr><tr><td bgcolor=#F8F8FF><font face=Arial size=2 color=#800000>Subject:</font> <font face=Arial size=2 color=#000000>" 
    $obj_thang->Subject "</font></td></tr><tr>
    </tr>
    </table></td>
    </tr>
    /table>
    </td>
    </tr><tr><td bgcolor=#F8F8FF><font face=Arial size=2 color=#800000>Message:</font> <font face=Arial size=2 color=#000000>" 
    $message "</font></td></tr><tr>
    </tr>
    </table>
    </table><a href=http://gmail.com target=_blank><font face=Arial size=2 color=#800000>Login to read message</a></font><br /></div></body>"
    ;

    }} echo 
    "<div align=center><font face=Arial size=4 color=#800000><b>" $m_empty "</b></font></div>";
    //close mailbox bi by bye
    imap_close($m_mail);

    ?>
    just incase any one is stuck with the same thing
    Last edited by phpcodelearner; 02-10-2010 at 10:03 PM. Reason: spelling misstake

  • #7
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Cool beans, please click the thank you button.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #8
    New to the CF scene
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have just created a Gmail class.. You can check them out at my blog.. =)
    Also, I have included another PHP file which runs the Gmail class. Hope that helps!


  •  

    Tags for this Thread

    Posting Permissions

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