As part of the registration process on a website, I have added mail confirmation. But for some reason, the mail function throws an Internal server error in there.
The strange thing is that if I create a test script, with the exact same email (all the same parameters) it works fine, and sends the email.
The mail is sent from a function in a Class, in case that helps. I didn't post the code because it isn't really relevant, even if I try mail('email#email.com','subject','email'); it fails with the 500 error!
The server error logs don't show anything at all, anyone knows what may cause such a problem?
Technology:
The server is running php through mod_fastcgi, although this problem also happens if I switch to mod_suphp.
Updates:
UPDATE:
I'll try to explain this better, the mail function works perfectly if called from another file, with the same parameters. The problem here is something that combined with the mail function causes an error 500. The rest of the file where it's called is fine too, if I comment the mail function everything works. The way it gets called is an AJAX request to a file that calls a function where the mail is sent (Just in case this helps)
UPDATE 2:
In response to answers so far, here is more information I did not share previously:
OS: CentOS release 5.8
When I say error 500, I mean that the server returns only an HTTP 500 status code.
The server does not show anything in any error log
The most important thing is that if I create a file called test.php, with only mail('address#domain.com','Subject','Message'), it works just fine. When called from this other file, 500 status code returned.
What I am asking is if anyone knows, probably from experience, what could be causing this.
UPDATE 3:
Someone had the same problem yesterday: PHP's mail() function causes a 500 Internal Server Error only after a certain point in the code
UPDATE 4:
After some testing, I have discovered that the 500 stats code is only returned when the script is called via AJAX. If I create a file called test.php, and I simply place the mail function and test it, it works. Calling it via AJAX doesn't, any ideas?
Your question is very confused.
You've not said what operating system you are running on, nor provided details of the configuration: on MSWindows php's mail function acts as an SMTP client. On POSIX OS's (including Linux) it executes a command program to send the email. The SMTP client needs to know the server and port to connect to. The POSIX function needs the config to tell it which program to run.
You keep refering to a 500 error - do you mean an HTTP 500 status code at the browser?
What does the log for the mail program / server show? If this is a posix platform, try changing the php.ini to run a shell script to log actions and parameters.
With the amount of input you have provided, it is very hard to tell, how that error occured.
Error: 500 are Interval Server Errors and can have more than one reasons for occuring.
A malformed php cgi script
An invalid directive in an .htaccess or other config file
Limitation imposed by file system and server software.
May be you are attachcing a file to be to be sent
Missing Line Breaks (\r\n) in the headers
Try every solution listed from this cPanel Forums
After some more hours of testing I have found the problem!
I was using window.location to redirect the user to a new page after the AJAX call was completed, in it's callback function.
Apparently if you modify it after an AJAX call to a php script that uses the mail() function, the server returns a 500 status code in the request
Related
I am using an external SOAP API (Interworx API - http://docs.interworx.com/interworx/api/index-Using-the-API.php#toc-Chapter-2) and when the SOAP call executes successfully I receive an 'ERR_NO_RESPONSE' or 'Unable to connect' or similar message in my browser (Chrome or Safari or Firefox). When the SOAP command does not succeed, the page works fine and I receive the appropriate return array in $result.
The call is:
$client = new SoapClient($interworx_soap_url);
$result = $client->route($api_key, $api_controller, $action, $input);
The $client->route() command is creating a new domain pointer in my control panel.
Interestingly, the API call always works, but somehow it is interrupting my code execution. I have tried adding an ob_start() and ob_clean() around these lines but it makes no difference.
So when my command $client->route() is successful (it creates a new domain pointer), it causes the problem (ERR_NO_RESPONSE in browser) but when the command is not successful (like when the domain pointer already exists) it works fine (returns the status array with the error message).
Any help solving or isolating the problem would be greatly appreciated. Incidentally, this problem does not generate any messages in my PHP or server Apache error log. Thanks!
OK, I found my problem and it was not exactly a coding issue. When I called the $client->route() command and a new pointer domain was created, the API also restarted Apache to make the new Server Alias live. This was killing my script at exactly that point! It turns out that there is a setting in Interworx that lets me force the restart to be "graceful" and this solved my problem. The code was all good. Thanks
We have a SOAP service that receives files as byte content. This service works fine for small files, but is failing for files ~25MB or larger. In the case of large files, the SOAP call executes but returns null. It literally returns nothing--no error message, no message at all. My associate indicated that the server is generating a 500 internal server error, which somehow gets back to the client but disappears in my testing. Tracing the code indicates that the handle() method of the code is not throwing an eror but also not doing anything at all--not calling the service's authorization method nor the method that puts the file to the server.
What is the likely cause of this problem, and how can I resolve it?
I think the client that calls the soap stop the service before having the answer.
Try to increase the value of default_socket_timeout in your php.ini.
You can also increase the value of max_execution_time
I hope it will help you. :)
I have a web app that allows the user to upload a pdf and it will then email it to us via swiftmailer. With some pdfs, the process fails.
I can verify that it crashes the php script, yet returns no php error. There's a 500 error from the server, but normally if there's a 500 error, php has a log of what the error was.
I have also verified that it crashes at the
$mailer->send($message);
line
Oddly, only some pdfs crash it, and those same pdfs work fine on the development server with identical code.
What could be causing php to crash without an error message?
After running several tests, I found that error logging was happening some of the time, but not others. I didn't figure out why that was so, however, I tried renaming the php-errors.log file so php would start with a new, fresh log file, and now errors are getting logged properly. I don't know why that worked, but I'll take it.
FYI, I've run into two things that can cause a PHP crash without an error message:
Script timeouts - A timeout may prevent an error message from being returned; in my particular case the script was waiting for an SMTP response when the timeout happened, which may have been why I didn't get a timeout message. Try changing your max_execution_time value in php.ini to 300 (5 minutes) and see if you can get an actual error message.
Folder permissions - I've encountered a case where insufficient folder permissions resulted in the script just halting without providing an error.
In the case of 2, I wrapped a try/catch clause around the line that was causing the halt, and I finally got an Exception to show up explaining about the permissions problem. That may be worth trying as a general response to silent crashes.
I am using the Codeigniter framework in a project - I have a tool which reads an array and sends out over 10,000 emails using the SwiftMailer Email framework.
One form which I have once submitted is supposed to send out each individual email, however it doesnt sent out all of them as after a period of time I get the following error:
404 Page Not FoundThe page you requested was not found. - 500.shtml
The page itself doesnt actually redirect anywhere else so cannot understand why it would be saying this - anyone have any ideas?
Thanks
It looks like you're actually ending up with a 500 error, but when CI tries to display the custom error page for a 500 error (500.shtml), it can't find it, and so throws a 404 instead. Check your logs for the cause of the 500 error.
It'll be a custom error page, probably set up on the web server itself. If it's an Apache server, check the httpd config and remove any ErrorDocument directives you don't want so you can see the actual error.
As Tom said, if this is happening after a significant delay, you're likely getting a timeout. The length of timeouts can be increased from the PHP end using set_time_limit() or the php.ini setting max_execution_time. However in general if you have a long-running task it is much better to run it in a background process than try to shoehorn it into an HTTP request.
So I just got a nasty surprise when I deployed some code I thought I'd tested. It would seem there must be some difference between my test machine and my server. The exact same code, featuring a header redirect, worked perfectly on my test machine and not at all on the server. The redirect on the server simply didn't happen, leaving a blank page as a result.
The header is called somewhere in the middle of the script - but nothing will have been output yet. It doesn't output anything until the very end of the script. Long after everything else is run. It buffers everything.
Both server and test machine are running the same PhP version, the same Apache version. Is there something in the configuration files that would allow the header to happen for one and not in the other? Is there something else going on here that would cause it to fail?
EDIT:
Here's the line that sets the header:
public function setRedirect($url) {
header('Location: '.$url);
}
And here's the code that calls that:
$url = new URL('index');
$this->layout->setRedirect($url->toString());
Where URL::toString() always generates a fully qualified domain name, in this case: http://domain/index.php?action=index
I checked both Php and Apache error logs. Nada.
Probably there was some whitespace or other form of output before the header call.
This is only work if you the ini setting output-buffering is on (or if you explicitly start output buffering, but in that case, the redirect should work in both computers).
You can confirm this by turning on error reporting.
Use Fiddler or some other client-side tool to check your headers. Determine that the Location: header is actually being sent. Also, some browsers are picky in the order that headers need to be sent.
I think the most likely explanation is that an error is causing the script to exit on your server, and you have display errors turned off (hence the blank screen). I would suggest checking the Apache error long on your server to see if PHP is putting something in there.
Otherwise you could use a browser extension like LiveHTTPHeaders (for Firefox) to see if the location header is being sent at all, or try debugging the script to see if it's even getting as far as that header call.
I think your server puts some script in your pages to track visitors and give you traffic stats or for a similar purpose. Ideally, you should get an error for this but may be your server has error reporting disabled which gives you a blank page.
I suggest you to run a script with a syntax error and check weather your server has error reporting disabled.