PHP Classes

Missing a post on busy times

Recommend this page to a friend!  >  All threads  >  Missing a post on busy times  >  (Un) Subscribe thread alerts  
Subject:Missing a post on busy times
Summary:Seems to miss reading a post if one bomes in while it's busy
Author:John Brohan
Date:2007-10-21 16:21:57
Update:2007-10-22 11:41:07

  1. Missing a post on busy times   Reply   Report abuse  
Picture of John Brohan John Brohan - 2007-10-21 16:21:57
I'm using this excellent class to receive mail to several addresses The messages typically include a jpeg attachment, so they are quite long. The php reads and stores the emails as .txt files, which are downloaded and interpreted by a program running on a slow laptop computer.
I do it this way because some of the images come directly from cell phones and these need to be 'unpicked' carefully. For the time being I'm doing this in another computer language.

If there are a lot of emails, or some ones with large images, I often lose an email.

I would be very happy if one of you could tell me where is my mistake or how to avoid this problem.

I include the php program.

Yours Sincerely

<?php session_start();
require ('');
$pop3 = new POP3;

// Connect to mail server
$do = $pop3->connect ('');
if ($do == false) {
echo 'Connected to mail server<br/>';

// Login to your inbox
$do = $pop3->login ('login', 'password');

if ($do == false) {
echo "logged in<br/>";
// Get office status
$status = $pop3->get_office_status();

if ($status == false) {
$count = $status['count_mails'];
echo "there are ".$count."emails waiting<br/>";
if ($count == '0') {
echo 'There are no new e-mails<br/>';

for ($i = 1; $i <= $count; $i++) {
$email = $pop3->get_mail($i);

if ($email == false) {
echo $pop3->error;
// print_r ($email);


$pos1 = strpos($Text,'To: ');
$pos2 = strpos($Text,chr(10),$pos1);
$To = substr($Text,$pos1,$pos2-$pos1);
// if ($To != '') break;
// echo "To =".$To."<br/>";
$pos1 = strpos($To,'@');
$username = trim(substr($To,0,$pos1));
$To = trim(substr($To,$pos1+1));
if(strtolower($To) != ''){
$username=''; // dump spam and junk
// echo "username=".$username."To = ".$To;
$pos1 = strpos($Text,'From: ');
$pos2 = strpos($Text,chr(10),$pos1);
$From = substr($Text,$pos1,$pos2-$pos1);
$pos1 = strpos($From,'<');
if ($pos1){
$pos2 = strpos($From,'>',$pos1);
$From = substr($From,$pos1+1,$pos2-$pos1-1);
$pos1 = strpos ($From,'@');
if ($pos1 > 0 ){
$phone = substr ($From,0,$pos1);
$pos1 = strpos($Text, 'Content-disposition: inline');
if ($pos1){
$pos1 = strpos($Text,chr(10),$pos1)+1;
$pos2 = strpos($Text,chr(10),$pos1);
$message= trim(substr($Text,$pos1,$pos2 - $pos1-1));
// echo "message= ".$message."<br/>";

$message = addslashes($message);
if ($username != ''){

$result=mysql_query("insert into WoundEmails (processed) values (0);");
if(!$result){die ('Database error insert into wound emails: ' . mysql_error());}
$descriptor = fopen ($filename, "w");
$res = fwrite($descriptor,$Text);
echo "username=".$username."*<br/>";
echo "File ".$filename." written with ".$res." characters <br/>";
echo "message=".$message."*<br/>";
$result=mysql_query("update WoundEmails set
username = '$username',
filename = '$filename',
FromSP = '$From',
ToEmail = '$To',
Subject = '$message'
where woundx = $RecordNumber;");
if(!$result){die ('Database error update woundemails: ' . mysql_error());}
mail('','WoundFollowUp Spam',$Text,$headers);
$res=$pop3->delete_mail($i); // delete the valid emails
echo "res=".$res."i=".$i;



  2. Re: Missing a post on busy times   Reply   Report abuse  
Picture of Steffen Stollfuß Steffen Stollfuß - 2007-10-22 11:41:10 - In reply to message 1 from John Brohan

I think you should try at first this correction of your fwrite line

$res = fwrite($descriptor,$Text,strlen($Text));

and you should have a look at the php.ini memory_limit of a script. Maybe that the scipt reachs the limit and don't work correctly anymore.


For more information send a message to info at phpclasses dot org.