Jump to content

Recommended Posts

I have this following code.

 

$mbox = imap_open("{mailbox:143/notls}INBOX", "username", "password") or die(imap_last_error()."<br>Connection Faliure!");

$MC = imap_check($mbox);

 

// Fetch an overview for all messages in INBOX

$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);

 

echo "<table border='1' cellpadding='5'>";

echo "<caption>Overview Output</caption>";

echo "<tr><th>Msgno</th><th>From </th><th>To</th><th>Subject</th></tr>";

 

foreach ($result as $overview) {

 

$header = imap_fetchheader($mbox,$overview->msgno);

$header = explode('X-Forwarded-For:', $header, 2);

$header = explode('myemail@gmail.com', $header[1], -1);

$emailTo = $header[0];

 

echo "<tr><td>#$overview->msgno {$overview->date}</td><td> " . $overview->from . " </td><td>" . $emailTo . "</td><td>$overview->subject</td></tr>";

 

echo "</table>";

....

 

For small number of emails, this code works fine. but as soon as message number increase and hits more then 50. Following error is encountered:

Maximum execution time of 30 seconds exceeded in imaptest.php

 

My goal is to extract an email just after X-Forwarded-For in imap_fetchheader.

 

I also tried

 

preg_match('/X-Forwarded-For:\s(.*)\smyemail@gmail.com/i',$header,$getText);

 

But this too triggers the same error : Maximum execution time of 30 seconds exceeded in imaptest.php

 

 

Is there any alternative method to achieve the result with better programming approach. How can make this code more faster .. or say lighter.

 

any alternatives/suggestions ?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/
Share on other sites

Use a script that supports mass mailing. PEAR Mailer is a good one, you might even consider PHPMailer (not sure if that supports mass mailing).

 

Pear::Mail is your best bet imo.

 

Your other option is to do it in stages, limit the query to 50 emails send. Or use set_time_limit and change the execution time to be more than 30 seconds, however if accessing from a browser the browser may time out. So yea.

 

Look into Pear::Mail for mass mailing :)

Hummm i have the stragest feeling that premiso likes Pear::Mail,

if you can't use it then a trick i used was a loop that send 100 mails, then auto-refreshed and send the next 100 mails etc etc.. it was a lazy trick but worked for a one off project.. :-[

Hummm i have the stragest feeling that premiso likes Pear::Mail,

if you can't use it then a trick i used was a loop that send 100 mails, then auto-refreshed and send the next 100 mails etc etc.. it was a lazy trick but worked for a one off project.. :-[

 

No, but I do not know of any other php mass mailer scripts. I actually have my own mailing script that creates a queue that sends 5 messages every 5 seconds that are in queue in my DB via a Cron Job.

 

I found that to work great, but I know that Pear::Mail has that functionality too, it just requires Pear :)

Oh don't get me wrong i agree, My 2nd Choice would be phpmailer (due to ease of use) but it is still limited, i have added to it but still limited hence my "workaround", I only said that because you said Pear Mail in 3 out of 4 paragraphs.

Oh don't get me wrong i agree, My 2nd Choice would be phpmailer (due to ease of use) but it is still limited, i have added to it but still limited hence my "workaround", I only said that because you said Pear Mail in 3 out of 4 paragraphs.

 

Yea, I get excited when posting and sometimes forget to watch how/what I type ;)

 

Reading that post now I do realize that I was totally promoting Pear::Mail lol. Whoops.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.