PHP contact form goes to a blank page -
my beloved php contact form goes blank page, email not going through either. i've added echo function @ end see if goes through entire code. worked, echoed line showing up. quite newbie in php, please don't bite head off. project i'm working on: http://www.designbynoemi.co.uk.
any direction highly appreciated.
and here code:
<?php /* * contact form class */ error_reporting(e_all); ini_set('display_errors', 1); header('cache-control: no-cache, must-revalidate'); header('expires: mon, 26 jul 1997 05:00:00 gmt'); header('content-type: application/json'); $admin_email = 'contact@designbynoemi.co.uk'; // email $message_min_length = 5; // min message length class contact_form{ function __construct($details, $email_admin, $message_min_length){ $this->name = stripslashes($details['name']); $this->email = trim($details['email']); $this->subject = 'contact website'; // subject $this->message = stripslashes($details['message']); $this->email_admin = $email_admin; $this->message_min_length = $message_min_length; $this->response_status = 1; $this->response_html = ''; } private function validateemail(){ $regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i'; if($this->email == '') { return false; } else { $string = preg_replace($regex, '', $this->email); } return empty($string) ? true : false; } private function validatefields(){ // check name if(!$this->name) { $this->response_html .= '<p>please enter name</p>'; $this->response_status = 0; } // check email if(!$this->email) { $this->response_html .= '<p>please enter e-mail address</p>'; $this->response_status = 0; } // check valid email if($this->email && !$this->validateemail()) { $this->response_html .= '<p>please enter valid e-mail address</p>'; $this->response_status = 0; } // check message length if(!$this->message || strlen($this->message) < $this->message_min_length) { $this->response_html .= '<p>please enter message. should have @ least '.$this->message_min_length.' characters</p>'; $this->response_status = 0; } } private function sendemail(){ $mail = mail($this->email_admin, $this->subject, $this->message, "from: ".$this->name." <".$this->email.">\r\n" ."reply-to: ".$this->email."\r\n" ."x-mailer: php/" . phpversion()); if($mail) { $this->response_status = 1; $this->response_html = '<p>thank you!</p>'; } } function sendrequest(){ $this->validatefields(); if($this->response_status) { $this->sendemail(); } $response = array(); $response['status'] = $this->response_status; $response['html'] = $this->response_html; echo json_encode($response); } } $contact_form = new contact_form($_post, $admin_email, $message_min_length); $contact_form->sendrequest(); echo "hello world!"; ?>
Comments
Post a Comment