Hash Change on Forum

I got it working :)I had to remove the action to go to the thank-you.html page.

I have a question, I’m not receiving any emails ! I’m current looking into this so I may solve before you read this but maybe not.

I did a PHP test and that worked. My only conclusion has to do with the form recipient but their is only one option for the email address.

It might be worthwhile just displaying what is return by submit.php

$("#contact_form").before('<p>' + data + '</p>');

Sorry that is not right. The data will be either

A -1 will indicate an error with the form validation.

A 1 will indicate success, but if you are not receiving the email then it will indicate an error with the code sending the email.

Since you are getting the Thank you message we know that it is 1. Therefore the problem must be with the email sending. That part of the script has a statement


Silly question : Do have you got $emailAddress defined to your email address?

No, I was going to place it between one of these lines, but I don’t think it may be effective.

	$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
		$body = "A user  $name submitted the contact form:\
		"Name: $name\
		"Email: $visitor_email \

I checked again and I have


located in submit.php.

I thought I solved it now I’m getting another PHP error.

Philip, I assume I can style the gray box that with the thank you message ? What about a redirect after 5-6 seconds to another part of my page ?

I thought I solved it now I’m getting another PHP error.

Have you resolved your PHP problem yet? Do you want to post your submit.php code on this post?


It was the presence of an assignment to $emailAddress that I was concerned about.

The PHPmailer has a config.php file where the configuration parameters such as the smtp server are defined. Have you set up this file correctly?

Have you resolved your PHP problem yet? Do you want to post your submit.php code on this post?

I’ve fixed one problem, but the PHP error persists. Here is the error I currently get;

Warning: require(phpmailer/class.phpmailer.php) [function.require]: failed to open stream: No such file or directory in /home/thecreat/public_html/construction/submit.php on line 2

Here is the file submit.php.

require "phpmailer/class.phpmailer.php";

session_name("fancyform");	/* starting the session */

foreach($_POST as $k=>$v)
	/* if magic_quotes is enabled, strip the post array */

	/* escape the special chars */

$err = array();

/* some error checks */
	$err[]='The name field is too short or empty!';

	$err[]='The email field is too short or empty!';
else if(!checkEmail($_POST['email']))
	$err[]='Your email is not valid!';

	$err[]='You have not selected a subject!';

	$err[]='The message field is too short or empty!';

/* compare the received captcha code to the one in the session array */
if((int)$_POST['captcha'] != $_SESSION['expect'])
	$err[]='The captcha code is wrong!';

/* if there are errors */
	/* if the form was submitted via AJAX */
		echo '-1';

	/* else fill the SESSION array and redirect back to the form */
	else if($_SERVER['HTTP_REFERER'])
		$_SESSION['errStr'] = implode('<br />',$err);

		header('Location: '.$_SERVER['HTTP_REFERER']);


/* the email body */
'Name:	'.$_POST['name'].'<br />
Email:	'.$_POST['email'].'<br />
IP:	'.$_SERVER['REMOTE_ADDR'].'<br /><br />

Message:<br /><br />



$mail = new PHPMailer();	/* using PHPMailer */

$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";



unset($_SESSION['post']);	/* unsetting */

/* the form was successfully sent */
	echo '1';

		header('Location: '.$_SERVER['HTTP_REFERER']);


/* some helpful functions */
function checkLen($str,$len=2)
	return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;

function checkEmail($str)
	return preg_match("/^[\\.A-z0-9_\\-\\+]+[@][A-z0-9_\\-]+([.][A-z0-9_\\-]+)+[A-z]{1,4}$/", $str);

The configuration file for the form does not have any SMTP settings.

I would recommend that you post this as a problem on the PHP forum. Somebody there will undoubtedly be able to advise you better.

Philip I’m in the process but can you remove the gray background where the line ‘thank you message sent’ appears?

the grey background is from the “background” style in

#Contact {
	background: #C0C0C0;
	overflow: hidden;
	width: 650px;
	margin: 40px 35px 0 300px;

changing it to

background: #000000;

should resolve the problem

Philip, I need to have the form check that the fields are filled in before sending the form then displaying a thank you message, if a field is not filled in the form can’t be sent.

Try replacing the javascript we added early with

<script type="text/javascript">

		// Code for validation of form content
		var name = $("#idname");
		var email = $("#idemail");
		var message = $("#idmessage");
		var captcha = $("#id6_letters_code");


		function validateName() {
			var a = name.val();
			if (a.length < 3) {
				alert("Please supply your name");
				return false;
			return true;

		function validateEmail() {
			var a = email.val();
			if (a.length == 0) {
				alert("An Email address must be supplied");
				return false;
			if (!/^[\\w\\.\\-]+@([\\w\\-]+\\.)+[a-zA-Z]+$/.test(a)) {
				alert("Email address is invalid");
				return false;
			return true;

		function validateMessage() {
			var a = message.val();
			if (a.length < 10) {
				alert("Please complete the message field");
				return false;
			return true;

		function validateCaptcha() {
			var a = captcha.val();
			if (a.length != 6) {
				alert("Captcha code is invalid");
				return false;
			return true;

		// End of Code for validation of form content


		// Plus validation in submit
		var invalid = !(validateName() && validateEmail() && validateMessage() && validateCaptcha());
		if (invalid) return e.preventDefault();

        $.post('/construction/submit.php', $(this).serialize(),
                var message;
                    message = "error";
                    message = "Thank your for the message";
                $("#contact_form").before('<p>' + message + '</p>');
// -->

Your html for the form should become

<form method="POST" id="contact_form" action="">
<div class="name">
<label for="idname">Name: </label>
<input type="text" name="name" id="idname" value="">
<div class="name">
<label for="idemail">Email: </label>
<input type="text" name="email" id="idemail" value="">
<div class="message">
<label for="idmessage">Message:</label>
<textarea name="message" id="idmessage" rows="5" cols="30"></textarea>
<div class="captcha"><img src="./site_construction_a.php_files/captcha_code_file.php" id="captchaimg"></div>
<div class="capcode">
<label for="id6_letters_code">Enter (above) code here :</label>
<input id="id6_letters_code" name="6_letters_code" type="text">
<div class="submit">
<input type="submit" value="Submit" name="submit">

Hi, that works but could the notification be on the right hand side of each of the form fields then highlight the form field ? Also the CAPTCHA is not displaying, although it’s in the HTML, unless I’m over looking something ?

I looked over the HTML and fixed what I could but the CAPTCHA continues not to show on the page.

What is going on with this line;

(!/^[\\w\\.\\-]+@([\\w\\-]+\\.)+[a-zA-Z]+$/.test(a)) { 

I did a save as from your original page to develop the new code, this constructs a sub directory and puts associated files in it. I have then cut and pasted the html code which is where the problem has crept in.

The src attribute of the img tag needs to be changed to reflect where it is on your site.

Hi, Philip could you past that part of the code so I can see which path it is, I’ve already tried a few but it’s not working :slight_smile:

Also would it be possible to get the form fields that are not filled out not to have a pop up but instead on the right hand side of the form a text message and the form hightlights in red ?

Philip I have solved the CAPTCHA problem. There remains something, the javascript is not submitted the form data using ajax as it should. If you want a link to the page in progress here.