views:

244

answers:

2

Hi,

I have (what I think) is a simple script to send a short mail:

<?php

$to = "[email protected]";

$subject = "Amendment required";
$message = "Employee: " . $_POST['employees'] . "<BR /><BR />Notes: " . $_POST['notes'] . "<BR /><BR />Reported By: " . $_POST['empID'] . ".";
$from = "[email protected]";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $from";
mail($to,$subject,$message,$headers);

?>

(I've changed the email addresses for privacy reasons)

When this is loaded, after a delay we get the error

"Fatal error: Maximum execution time of 30 seconds exceeded..." - but the mail is sent successfully.

Am i missing something simple here?

Many thanks in advance

leddy

+1  A: 

Try using set_time_limit(0) to remove the PHP Execution time limit. It might not work properly if you have safe_mode on, but it should work otherwise.

Jimmie Lin
This is curing the symptom, but not the cause.
Gordon
If he's looping and sending lots of emails, it could happen easily. mail() is SLOW. I've seen it take 4-5 seconds to send 6 emails.
Erik
+3  A: 

Sending a single E-Mail using mail should not take 30 seconds. Never. You should talk to the server administrator unless you are sending out mail to hundreds or thousands of recipients, or the E-Mail is dozens of megabytes big. It seems, though, that neither is the case. I would guess that the sendmail command PHP is calling internally is taking too long to respond for some reason.

Is this the full script you are executing?

Pekka
Look at the original post, below the PHP tag. 'etc' is written there, so there should be something resource incentive in that (apparently, but not) irrelevant piece of code.
Jimmie Lin
that shouldn't be the reason for the timeout, because according to the OP, the E-Mail is sent out (the timeout would occur before that)
Pekka
This might sound a bit strange, but what if the timeout is triggered precisely after the mail is sent in the PHP Core, and not after the function returns? I'm not sure if that's even possible, but anyway.
Jimmie Lin
The 'etc' is my mistake, don't actually know how it got there :-\There is no other code, this is the full script, and it is one email, to one address and it has at most 5 lines of text. I will speak to the server guy, but is there something I should mention specifically? Thanks for the responses
leddy
i would suspect DNS taking too long to return or similar mechanism, so PHP has to wait.
dusoft
Then the PHP Mail system is just taking time. Use the `set_time_limit` as a workaround, I can't think of a better way right now.
Jimmie Lin
Before you contact the admin, one more shot in the dark: Can you try removing all additional headers (lines 8,9,10)? Can you try a different recipient E-Mail address? If all that doesn't change anything, just show the admin the script and tell him it's breaking the 30 second PHP timeout, it should be enough for him to act on.
Pekka
ok thanks guys, i will try the above and let you know how I get onCheers
leddy
I tried removing the headers (didn't change anything), then changing the email address, and now I get the error:Warning: mail() [function.mail]: SMTP server response: 530 Relaying not allowed in..and the mail doesn't send - so I changed it all back to what it was and i'm still getting this error - can't speak to admin yet, but is there anything I can do about this? Thanks
leddy
I meant changing the recipient address (to see whether there are any routing issues between your server and the recipient's one). The sender must probably be on your domain for it to work.
Pekka
I did change the recipient to an external address - and the sender address is just a made up address (this does work as I have it in another script), but I changed it to an actual user and this doesn't work either, bizarre!
leddy