Contact form not working need help

I have a template and I just do not understand php or how it works, For the life of me I can not get this contact form to work.
yes I know I probably shouldn’t use php if i don’t understand it, and yes I know this is probably a simple fix, but after watching videos and looking up different scripts I have all but given up.

I would appreciate any help,
Thanks

FORM:

[php]

Get in Touch

We’re currently accepting new clients. We look forward to being there on your special day.

<!-- Contact Form -->
<div class="row">
	<div class="span9">

    	<form id="contact-form" class="contact-form" action="_include/php/contact.php">
        	<p class="contact-name">
        		<input id="contact_name" type="text" placeholder="Full Name" value="" name="name" />
            </p>
            <p class="contact-email">
            	<input id="contact_email" type="text" placeholder="Email Address" value="" name="email" />
            </p>
            <p class="contact-message">
            	<textarea id="contact_message" placeholder="Your Message" name="message" rows="15" cols="40"></textarea>
            </p>
            <p class="contact-submit">
            	<a id="contact-submit" class="submit" href="#">Send Your Email</a>
            </p>

            <div id="response">

            </div>
        </form>

    </div>

[/php]

THIS IS THE CONTACT.PHP

[php]<?php
/*

  • Contact Form Class
    */

header(‘Cache-Control: no-cache, must-revalidate’);
header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT’);
header(‘Content-type: application/json’);

$admin_email = ‘[email protected]’; // Your 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 = 'Hello, Enamored Photo'; // 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 your name</p>';
		$this->response_status = 0;
	}

	// Check email
	if(!$this->email)
	{
		$this->response_html .= '<p>Please enter an e-mail address</p>';
		$this->response_status = 0;
	}

	// Check valid email
	if($this->email && !$this->validateEmail())
	{
		$this->response_html .= '<p>Please enter a 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 your message. It should have at 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();

?>
[/php]

First thing I notice is that for a person who doesn’t know PHP this script you chosen is way above your level. It’s using Object-Oriented Programming which is the the next level above the procedural way of doing it.

I have one question is it an absolute must that you use the template?

I’m sure you can find a simple procedural php script by doing a Google search…

I would simply validate an email address this way:

[php] // Method returns a Boolean if the user’s email is valid:
public function hasValidEmail() {
return (!filter_var($this->email, FILTER_VALIDATE_EMAIL));
}[/php]

[php] if ($user->hasValidEmail()) {
$errorMsg[3] = ‘Email is invalid, please re-enter.’;
$flag = true;
}[/php]

I have in the past tried to RegEx for validating email in the past and found out it doesn’t work the way you think it should. I find it best just to use php built-in method (function).

Sponsor our Newsletter | Privacy Policy | Terms of Service