Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

+9500 mails ... OUCH ! 1

Status
Not open for further replies.

Sleidia

Technical User
Joined
May 4, 2001
Messages
1,284
Location
FR

Hello,

I'm not sure if it is a PHP question or a RedHat question but here is what happened to me today.

I have set up a php script that is called once I receive a mail to a particular mail account thanks to this line added in my aliases :
my_alias |"/path_to_php_as_cgi/php /path_to_my_script/script.chp"

As you can see, the php script uses the CGI version of PHP. The script does a few things and send me an email when the task is finished.

The problems started when the script ran endlessly, thus sending me more than 9500 emails.

Although the mail() command is outside of any loop, I don't understand the reason why the script has been called forever. I had to delete the script on the server to stop this crazy self-spamming.

So, is there something I should do to prevent this to happen again? Note that the script worked greatly on a freeBSD system. So why on earth would it run endlessly on this RedHat thing.

Thanks for the helping.



 
Hello Sleipnir,

I use Sendmail and the script send an email to my private email which is different from the one that triggers the script.

I've already spent hours to search for the cause and it's beyond my comprehension.

Here is the script triggered by the mail alias :

<?php

$mbox = imap_open (&quot;{mail.my_domain.com:110/pop3}INBOX&quot;, &quot;scripts_account&quot;, &quot;account_password&quot;);

$check = imap_check ($mbox);

if($check) {

$mess_num_all = $check->Nmsgs;
$mess_num_unread = $check->Recent;
$mess_start_save = $mess_num_all - $mess_num_unread;

if($mess_num_unread == 0) {

} else {

for($i=$mess_start_save+1; $i <= $mess_num_all; $i++ ) {

$header = imap_header($mbox, $i);

$mess_subject = $header->subject;

$mess_from_full = $header->fromaddress;
$mess_from_adr = trim(str_replace(&quot;<&quot;, &quot;&quot;, str_replace(&quot;>&quot;, &quot;&quot;, strstr($header->fromaddress, '<'))));

$mess_date = date(&quot;Y-m-d&quot;,$header->udate);
$mess_time = date(&quot;H:i&quot;,$header->udate);

$mess_body = imap_fetchbody($mbox, $i, &quot;1&quot;);

/* ACTION 1 -----------------------------------------------------------------*/
if($mess_subject == &quot;do_stuff&quot;) {

// do stuff here

} else {

}

imap_delete($mbox, $i);

}

}

} else {

}

imap_close($mbox);

// test if the script was called
mail(&quot;my_account@my_domain.com&quot;, $mess_subject . &quot;DONE&quot;, &quot;&quot;, &quot;From: my_script&quot;, &quot;my_script@my_domain.com&quot;);

?>

Thanks
 

Well, I've finally found the problem, which made me remember how stupid I am ;( ... soooo stupid.

I was watching in the wrong direction : the problem came from the mail function with the wrong syntax.

It should be
mail(&quot;my_account@my_domain.com&quot;, $mess_subject . &quot;DONE&quot;, &quot;&quot;, &quot;From: my_script<my_script@my_domain.com>&quot;);
instead !

Such a function I use on a daily basis ... need some rest :)

Thanks for caring Sleipnir !


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top