So i’m making an email form in index.html with php mail() function in a php file. I’ve used the mail function in Github and it returned an 405 error as it should because its a static site.
When I try to run it on infinityfree I get the php returned back html text even I have another PHP file that connects to mySql database and I want it to trigger the function and atleast give me an error code instead of returning back as text.
Please note that only scripts with the .php extension are processed as PHP code. Files with the .html extension are assumed to be static HTML only and are sent to visitors as-is, including anything that would have been processed as valid PHP code.
The URL at http://boriso.infinityfreeapp.com/mail.php does not show the source code to me though, it just shows a blank page. When I check the Network tab in my browser I see the status code of the page is 500, which means the PHP code on the page has crashed.
Finally, please note that the PHP mail() function is heavily restricted on free hosting to the point where it cannot be used for almost everything. If you want to be able to send email, you best bet is to use a third party SMTP service.
We’ve created an example contact form template with PHPMailer, ReCaptcha and provided instructions on how to use it with Gmail’s SMTP server.