Jump to content

jpratt

Members
  • Posts

    144
  • Joined

  • Last visited

    Never

Everything posted by jpratt

  1. this is a simple way of using the class: $mail = new GetMail("server", "username", "password", "pop3", ""); $msg = $mail->num_msg(); //get number of messages for the offset $num = $msg - 1; if ($msg > 0) { $headers = $mail->headers($msg - $num, $num); foreach ($headers as $uid=>$header) { //date of message $datemsg = $header->date; //subject $subjectmsg = $header->subject; //who its from $from = $header->from; //message text foreach ($mail->body($uid, FT_UID) as $i=>$part) { if ($part['MIMETYPE'] == "TEXT/PLAIN") { $text = $part['DATA']; } } //echo or store your data here } } Hope it works for you. It uses the imap module so you can adjust the class to perform how you like. http://us3.php.net/imap
  2. you might need to if not already installed. depends if your server is on a windows machine or linux.
  3. Some of this might be helpful: http://us3.php.net/set_time_limit There is a time limit you can adjust for running scripts on your server.
  4. I have a class that uses the imap extention. Here is the code for it: <?php //if (!extension_loaded("imap")) { // dl("php_imap.dll"); //} class GetMail { private $host; private $user; private $pass; private $type; private $mbox; private $port; private $mh = null; function __construct($host, $user, $pass, $type = 'imap', $mbox = 'INBOX', $port = null) { $this->host = $host; $this->user = $user; $this->pass = $pass; $this->type = strtolower($type); if (is_null($port)) { switch($this->type) { case 'imap' : $this->port = 143; break; case 'pop3' : $this->port = 110; break; case 'nntp' : $this->port = 119; break; } } else { $this->port = $port; } $this->mbox = $mbox; $mailbox = "$this->host:$this->port/$this->type"; $this->mh = imap_open("{" . $mailbox . "}$this->mbox", $this->user, $this->pass, 16); } function __destruct() { if ($this->mh) { imap_close($this->mh); } } function num_msg() { return imap_num_msg($this->mh); } function num_recent() { return imap_num_recent($this->mh); } function headers($offset = 1, $max = 0) { $msg_from = $offset; if ($max > 0) { $msg_to = min($max + $offset, $this->num_msg()); } else { $msg_to = $this->num_msg(); } $headers = array(); for ($i = $msg_from; $i <= $msg_to; $i++) { $headers[imap_uid($this->mh, $i)] = imap_headerinfo($this->mh, $i); } return $headers; } function format_address($obj) { if (isset($obj->personal)) { return imap_rfc822_write_address($obj->mailbox, $obj->host, $obj->personal); } else { return imap_rfc822_write_address($obj->mailbox, $obj->host, ''); } } function format_address_list($array, $sep = ", ") { $list = array(); foreach($array as $obj) { $list[] = $this->format_address($obj); } return implode($sep, $list); } private function _decode_body($encoding, $part) { switch($encoding) { case 3: // Base64 $strPart = imap_base64($part); break; case 4: // Quoted printable $strPart = imap_qprint($part); break; case 0: // 7bit case 1: // 8bit case 2: // Binary case 5: // Other default: break; } return $part; } private function _mimetype($structure) { $mime_type = array("TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER"); if($structure->subtype) { return $mime_type[(int) $structure->type] . '/' . $structure->subtype; } return "TEXT/PLAIN"; } private function _get_mime_parts($struct, $msg, &$parts, $options = 0, $part_number = false) { switch ($struct->type) { case 0 : // TEXT case 2 : // MESSAGE case 3 : // APPLICATION case 4 : // AUDIO case 5 : // IMAGE case 6 : // VIDEO case 7 : // OTHER if(!$part_number) { $part_number = "1"; } $data = imap_fetchbody($this->mh, $msg, $options, $part_number); $parts[] = array( "DATA" => $this->_decode_body($struct->encoding, $data), "MIMETYPE" => $this->_mimetype($struct) ); break; case 1 : // MULTIPART $prefix = ""; while(list($index, $sub_struct) = each($struct->parts)) { if($part_number) { $prefix = $part_number . '.'; } $this->_get_mime_parts($sub_struct, $msg, $parts, $options, $prefix . ($index + 1)); } break; } } function body($msg, $options = 0) { $parts = array(); $struct = imap_fetchstructure($this->mh, $msg, $options); $this->_get_mime_parts($struct, $msg, $parts, $options); return $parts; } function delete_email() { //delete email in box imap_delete($this->mh,'1:*'); // to clear out an entire mailbox. imap_expunge($this->mh); } } ?> Careful calling the delete_email method. It will remove the email and will not be existent even in your deleted items on your mail server. then you connect with something like this: $mail = new GetMail("server", "username", "password", "pop3", "");
  5. It appears that you may not have broken your tables down enough. might help to have an items table, a customer table, and a booking table between the two. This would make it so you didn't have to repeat the item details on every entry. Also if an item description changed you would only have to change the one entry to update the item. You can do what you are try in two ways, store everything in an array and loop through that way, or run the query and insert the data in your booking table as the query loops through your results. EDIT Either way you are looping thru an array.
  6. I found the reason. Some of the emails were coming in as quoted printable strings. There are two functions that decode this. http://uk2.php.net/manual/en/function.quoted-printable-decode.php and if using the imap module for email: http://uk2.php.net/manual/en/function.imap-qprint.php I use the imap module to get my email so I will probably just work that into my class. Thanks for all the suggestions.
  7. I do have the following as the message is coming into the db: $text = htmlspecialchars($text, ENT_QUOTES); The strange thing is that it only does it to some emails coming in but not all.
  8. i dont think these thing will help but dont put a space when getting the post value $_POST[ "screen_type"] use this instead $_POST["screen_type"]. Also good html has closing tags, so your option tags need to close.
  9. Looking at the site and going thru the process it looks like the session is still there because it writes the session cookie name to my machine. there is just a problem with the variable from the post im guessing.
  10. try putting a session_start() on the third page. Edit: Make sure and put it before everything else.
  11. this is true in some cases. Depends on the auto start setting in the php.ini file if he needs the second session_start(); declaration. Either way if sessions were on, his code would still work just give a warning that the session was already started.
  12. if you are working with various forms you can pass data using hidden fields, or if is insensitive small ammounts of data you can pass it the url with GET, or you can store a cookie on a users machine, or like you are trying you can use a session variable. If this is not working you might have sessions not allowed in your php.ini file.
  13. Setup a cronjob to send to all email subscribers on the 24th then at a set time. In the job just do a query for the most recent products they subscribe to.
  14. I am connecting to an email account, reading its contents and placing it in a database. everything looks good but some of the text comes formated strange. some of it looks like this: I use the fine-cut nozzles on my Hyperthreme 1250. I am having the same pro= blem on=20 As you can see it cuts off sentences midword, places an = sign, and end of sentences it places and =20. Does anyone know what causes this? I tried a few different string functions on it to clear it up, but nothing helped. Can someone give me an idea what is going on? Thanks.
  15. Im using the following but it still includes some header information and does not remove the email below the message. function parse_email ($email) { // Split header and message $header = array(); $message = array(); $is_header = true; foreach ($email as $line) { if ($line == '<HEADER> ' . "\r\n") continue; if ($line == '<MESSAGE> ' . "\r\n") continue; if ($line == '</MESSAGE> ' . "\r\n") continue; if ($line == '</HEADER> ' . "\r\n") { $is_header = false; continue; } if ($is_header == true) { $header[] = $line; } else { $message[] = $line; } } // Parse headers $headers = array(); foreach ($header as $line) { $colon_pos = strpos($line, ':'); $space_pos = strpos($line, ' '); if ($colon_pos === false OR $space_pos < $colon_pos) { // attach to previous $previous .= "\r\n" . $line; continue; } // Get key $key = substr($line, 0, $colon_pos); // Get value $value = substr($line, $colon_pos+2); $headers[$key] = $value; $previous =& $headers[$key]; } // Parse message $message = implode('', $message); // Return array $email = array(); $email['message'] = $message; $email['headers'] = $headers; return $email; } Anyone done this before and have a way of doing this?
  16. I am using the pop3 class found at: http://www.phpclasses.org/browse/package/1120.html. Everything is working but I want to format the email to get rid of all the header information, and if possible all the replied emails below the main content. So if an email is a reply it does not contain the original email below it. Any ideas?
  17. I have the following code: $source = '/vservers/essmedcom/htdocs/downloader/software/' . $i; $target = '/vservers/essmedcom/htdocs/downloader/download/archive' . $i . '.zip'; $command = "/usr/bin/zip -r '$target' '$source'"; my problem is it zips the files i want to have at the root of the archive zip folder deep in the folders. I want to have it zip up files located at the software folder and place them at the root of the archive folder it creates. I tried this but didnt work to eliminate some of the folders deep: $source = '/vservers/essmedcom/htdocs/downloader/software/' . $i; $target = '/downloader/download/archive' . $i . '.zip'; $command = "/usr/bin/zip -r '$target' '$source'"; Any ideas? Thanks.
  18. Say i have a table with values like the following: ID: Name: 1 Bob 2 Bob 3 Bob 4 Nick 5 Nick How would i get the value of Bob based off of the fact that it occurs most in the field? Im trying to write a query that selects the three values that occur most in a field. Any ideas? Thanks.
  19. I have two timestamps comming in from a mysql database. For my testing Im using the following stamps: 2007-12-17 15:30:00 2007-12-17 17:00:00 My page needs to display a select box with the values between the stamps every half an hour. so in this instance it should loop and display the following values in the box: 3:30 pm 4:00 pm 4:30 pm I have played with the following without luck: while ($stime != $etime) { echo "<option value='" . $stime . "'>" . date("g:i a", strtotime($stime)) . "</option>"; $stime = date("i", strtotime($stime)) + 30; } The ideo is to loop through until the start and end stamps match. Any idea on how to do this?
  20. Thanks, works great! I did not know strtotime had this problem. Im working on a function that splits the times based on a selected time. The time will ultimately be stored as datetime in a mysql db. Thanks for the help.
  21. I am storing date/time formatted like this: 04-23-2008 12:00 I have the following code to output a string as a date. My ultimate goal it to find differences between dates and split them based on appointments made. I have the following code: $timestr = "04-23-2008 11:00"; echo date('m-d-Y h:i', strtotime($timestr)); My only problem is it returns 12-31-1969 05:00, not the date/time given it. How do I convert the string to a timestamp to work with and get the correct date/time? Thanks.
  22. set up a cron job on your server to call a specific php file. google cron jobs to see how it works.
  23. I am building a scheduling ap for someone. Does anyone know of a class already made to do this? So for instance an instructor puts down they are available from 2-6pm one evening and a student makes an appointment for 3-4pm, so it would have to be able to reserve that time yet make available 2-3pm and 4-6 for the teacher. Anyone seen this before? Thanks.
  24. or look into jquery and the calendar selectors there I have found a few from there. Plus its all free.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.