apache - Server doesn't parse php code fully -
since few days server doesn't parse php code (not attached file) anymore. if call php file via html file load forever. code tested on local apache2 server , there works fine. tried reinstall php5/apache2 on server still no progress.
the servers runs ubuntu 14.04 lts.
<?php if(isset($_post['email'])) { $email_to = "placeholder@placeholder.com"; $email_subject = "website contact"; function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_post['name']) || !isset($_post['email']) || !isset($_post['message'])) { died('we sorry, there appears problem form submitted.'); } $name = $_post['name']; $email = $_post['email']; $message = $_post['message']; $email_message = "form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "name: ".clean_string($name)."\n"; $email_message .= "email: ".clean_string($email)."\n"; $email_message .= "message: ".clean_string($message)."\n"; // create email headers $headers = 'from: '.$email."\r\n". 'reply-to: '.$email."\r\n" . 'x-mailer: php/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <html> <p>succesful!</p> </body> </html> <?php } ?>
´
define function outside if statements. not sure reason error @ least reads more logically. indent code sensibly helps lot when looking errors.
also <p>
tags belong on <body
, not in <html>
section of html code.
also if have issues on live server, add error reporting script, remember on live servers errors written logs, write screen while fox bug easier see whats going wrong
<?php error_reporting(e_all); ini_set('display_errors', 1); function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , fix these errors.<br /><br />"; die(); } if(isset($_post['email'])) { $email_to = "placeholder@placeholder.com"; $email_subject = "website contact"; // validation expected data exists if(!isset($_post['name']) || !isset($_post['email']) || !isset($_post['message'])) { died('we sorry, there appears problem form submitted.'); } $name = $_post['name']; $email = $_post['email']; $message = $_post['message']; $email_message = "form details below.\n\n"; $email_message .= "name: ".clean_string($name)."\n"; $email_message .= "email: ".clean_string($email)."\n"; $email_message .= "message: ".clean_string($message)."\n"; // create email headers $headers = 'from: '.$email."\r\n". 'reply-to: '.$email."\r\n" . 'x-mailer: php/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } ?> <html> <body> <p>succesful!</p> </body> </html>
Comments
Post a Comment