Jump to content

PHP contact forms noob problem help please


drickles

Recommended Posts

i need help getting the contact us page on my website to work. We are a team of two with me dealing with the html and the css whiles the other deals with the php but now my other half isnt available and ive got myself a little trouble.

 

this is how my form id is structured in my html code

<form id="ajax-contact-form" action="contact.php" class="contact_form">                                
                                <input type="text" class="required" name="name" value="Name" title="Name" />
                                <input type="text" class="required" name="email" value="Email" title="Email" />
                                <input type="text" name="subject" value="Subject" title="Subject" />                            
                                <textarea name="message" class="required" id="message" title="Message">Message</textarea> 
                                <input type="reset" class="send_btn" value="Clear form" />
                                <input class="send_btn" type="submit" value="Send message!"> 
                            </form> 

now here is where i get confused. The template i am modifying does not come with a contact.php. all i seemed to find was a folder named contact_form which contained two php files named contact_process.php and email_validation.php..these are their codes respectively

 

contact_process.php

<?php

include dirname(dirname(__FILE__)).'/mail.php';

error_reporting (E_ALL ^ E_NOTICE);


$post = (!empty($_POST)) ? true : false;

if($post)
{
include 'email_validation.php';

$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);


$error = '';

// Check name

if(!$name)
{
$error .= 'Please enter your name.<br />';
}

// Check email

if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}

// Check message (length)

if(!$message || strlen($message) < 10)
{
$error .= "Please enter your message. It should have at least 10 characters.<br />";
}


if(!$error)
{
$mail = mail(CONTACT_FORM, $subject, $message,
     "From: ".$name." <".$email.">\r\n"
    ."Reply-To: ".$email."\r\n"
    ."X-Mailer: PHP/" . phpversion());


if($mail)
{
echo 'OK';
}

}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}

}
?>

email_validation.php

<?php
function ValidateEmail($value)
{
	$regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i';

	if($value == '') { 
		return false;
	} else {
		$string = preg_replace($regex, '', $value);
	}

	return empty($string) ? true : false;
}
?>

i couldnt make sense of what was going on in the codes until i realized there was another php file in the root directory named mail.php. i opened it and saw this

<?php
// Where will you get the forms' results?
define("CONTACT_FORM", 'xxxxxxx@domain.com');
?>

now this actually made me happy because i thought everything would be owk by just filling up that mail.php file with the right email. except upon uploading the site files and testing my contact us page i still dont get an email. 

 

is there something im doing wrong? i also got an idea to input a forwarder email into the mail.php instead of my direct email  to see if it would work. am i suppose to run something on my cpanel to make it work? please any form of help will be really helpful

Link to comment
Share on other sites

Since the contact.php doesn't exist. Try changing your forms action to contact_process.php it may need to be 'contact_form/contact_process.php' 

thanks buddy. so after many hours spent on trying to fix the problem i just realized one thing. my server does not support smtp. without that the mail.php script is bound to never work right?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.