Jump to content

Some Form Help


herghost

Recommended Posts

Hi all,

 

firstly apologies if this is in the wrong section, I couldn't decide on php or ajax! Basically my problem is this. I have a form (code below) that simply sends the fields via email. basically what happens is that the form will say its sent and not throw up any errors, I get the 'message successfully sent' note, however nothing appears in my inbox! I hope someone can see whats wrong:

 

Ok this is the page with the actual form:

<html>
<head>
<title>Blue-print Financial Soloutions - Contact Us</title>
<script type="text/javascript" src="js/functionAddEvent.js"></script>
<script type="text/javascript" src="js/contact.js"></script>
<script type="text/javascript" src="js/xmlHttp.js"></script>
<style type='text/css' media='screen,projection'>
<!--

fieldset { border:0;margin:0;padding:0; }
label { display:block; }
input.text,textarea { width:300px;font:12px/12px 'courier new',courier,monospace;color:#333;padding:3px;margin:1px 0;border:1px solid #ccc; }
input.submit { padding:2px 5px;font:bold 12px/12px verdana,arial,sans-serif; }

-->
</style>
    </head>
<?php include("nav.php"); ?>

<table width="700" height="40" border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="4a0073" bgcolor="4a0073">
  <tr> 
    <td><h3>Contact us</h3></td>
  </tr>
</table>
<table width="700" border="1" align="center" cellpadding="10" cellspacing="0" bordercolor="4a0073" bgcolor="#FFFFFF">
  <tr> 
    <td width="675" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="15">
        <tr> 
          <td align="left" valign="top">
<h1 align="left"> </h1>
<h1 align="center">Contact our head office...</h1><br>
		<h2 align="center">Call : 01362 853477</h2>
            <p id="loadBar" style="display:none;">
	<strong>Please Wait - Sending contact form;</strong>
	<img src="img/loading.gif" alt="Loading..." title="Sending Email" />
</p>
<p id="emailSuccess" style="display:none;">
	<strong style="color:green;">Success! Your Email has been sent.</strong>
</p>
		<div align="center"><span class="text"><font class="text">or email: 
              <a href="mailto:enquiry@blueprintmoney.com">enquiry@blueprintmoney.co.uk</a></font></span></div>
            <p align="center">Our head office staff will be happy to answer your 
              queries by telephone; <br>
              <strong>Monday to Saturday 9am - 5pm. </strong></p>
            <table width="425" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#4A0073">
		  <div id="contactFormArea">
	<form action="scripts/contact.php" method="post" id="cForm">
		<fieldset>
		  <tr>
				<td width="100%" height="20">
					<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#4a0073">
						<td width="20" height="20"><img src="images/form_top_left.gif"></td>
						<td height="20" width="100%"></td>
						<td width="20" height="20"><img src="images/form_top_right.gif"></td>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table width="425" border="0" align="center" cellpadding="5" cellspacing="5" bgcolor="#4A0073">
					  <tr class="white"> 
						  <td colspan="2"> <div align="center">Alternatively, complete the 
							  form below and we will get back to you at the earliest opportunity:</div></td>
					  </tr>
					  <tr class="whitebold"> 
						<td align="right"><label for="posName">Name:</label></td>
						<td><input class="text" type="text" size="25" name="posName" id="posName" /></td>
					  </tr>
                           <tr class="whitebold"> 
						<td align="right"><label for="posPhone">Phone:</label></td>
						<td><input class="text" type="text" size="25" name="posPhone" id="posPhone" /></td>
					  </tr>
					   <tr class="whitebold"> 
						<td align="right"><label for="posEmail">Email:</label></td>
						<td><input class="text" type="text" size="25" name="posEmail" id="posEmail" /></td>
					  </tr>
					  <tr class="whitebold"> 
						<td align="right"> <label for="posRegard">Postcode:</label></td>
						<td><input class="text" type="text" size="25" name="posRegard" id="posRegard" /></td>
					  </tr>
					  <tr class="whitebold"> 
						<td align="right"> <label for="posText">Nature of Enquiry:</label></td>
						<td><textarea cols="50" rows="5" name="posText" id="posText"></textarea></td>
					  </tr>
                          <tr class="whitebold"> <label for="selfCC">
			    <td><input type="checkbox" name="selfCC" id="selfCC" value="send" /> Send CC to self
		      </label></td>
                         
					  <tr class="white"> 
						<td valign="top" colspan="2" align="center">I am happy for blueprint financial solutions to contact me to discuss my requirements</td>
					  </tr>
					  <tr> 
						<td colspan="2" align="center"><label>
				<input class="submit" type="submit" name="sendContactEmail" id="sendContactEmail" value=" Send Email " />
			</label>
                
</td>
					  </tr>
				 </table>
			</td>
		  </tr>
		  <tr>
				<td>
					<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#4a0073">
					<td width="20" height="20"><img src="images/form_bottom_left.gif"></td>
					<td height="20" width="100%"></td>
					<td width="20" height="20"><img src="images/form_bottom_right.gif"></td>
					</table>
				</td>
			</tr>
		  </fieldset>
	</form>
            </table>
            
            </p>
            
          <br><br><p align="center"> </p></td>
        </tr>
      </table> 
     </td>
  </tr>
</table>
<?php include("bottom.php"); ?>

 

Nav & Bottom are just a header and footer and so dont need to be displayed here

 

This is contact.php

 

<?php
// Change the 4 variables below
$yourName = 'Dave';
$yourEmail = 'herghostuk@gmail.com';
$yourSubject = 'New Message';
$referringPage = 'http://www.blueprintmoney.co.uk/contact.php';
// No need to edit below unless you really want to. It's using a simple php mail() function. Use your own if you want
function cleanPosUrl ($str) {
return stripslashes($str);
}
if ( isset($_POST['sendContactEmail']) )
{
$to = $yourEmail;
$subject = $yourSubject.': '.$_POST['posRegard'];
$message = cleanPosUrl($_POST['posText'])."; <".cleanPosPhone($_POST[['posPhone']).">\r\n";
$headers = "From: ".cleanPosUrl($_POST['posName'])." <".$_POST['posEmail'].">\r\n";
$headers .= 'To: '.$yourName.' <'.$yourEmail.'>'."\r\n";
$mailit = mail($to,$subject,$message,$headers);
	if ( @$mailit ) {
	header('Location: '.$referringPage.'?success=true');
	}
	else {
	header('Location: '.$referringPage.'?error=true');
	}
}
?>

 

and xhtmlrequest which deal with the inputs and the sending

 

<?php
// change the 4 variables below
$yourName = 'Dave';
$yourEmail = 'herghostuk@gmail.com';
$yourSubject = 'New Message';
$referringPage = 'http://www.blueprintmoney.co.uk/contact.php';

// no need to change the rest unless you want to. You could add more error checking but I'm gonna do that later in the official release

header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';

echo '<resultset>';

function cleanPosUrl ($str) {
$nStr = $str;
$nStr = str_replace("**am**","&",$nStr);
$nStr = str_replace("**pl**","+",$nStr);
$nStr = str_replace("**eq**","=",$nStr);
return stripslashes($nStr);
}
if ( $_GET['contact'] == true && $_GET['xml'] == true && isset($_POST['posText']) ) {
$to = $yourName;
$subject = 'AJAX Mail: '.cleanPosUrl($_POST['posRegard']);
$message = cleanPosUrl($_POST['posText'])."; <".cleanPosPhone($_POST[['posPhone']).">\r\n";
$headers = "From: ".cleanPosUrl($_POST['posName'])." <".cleanPosUrl($_POST['posEmail']).">\r\n";
$headers .= 'To: '.$yourName.' <'.$yourEmail.'>'."\r\n";
$mailit = mail($to,$subject,$message,$headers);

	if ( @$mailit )
	{ $posStatus = 'OK'; $posConfirmation = 'Success! Your Email has been sent. Hope you enjoyed your stay.'; }
	else
	{ $posStatus = 'NOTOK'; $posConfirmation = 'Your Email could not be sent. Please try back at another time.'; }

	if ( $_POST['selfCC'] == 'send' )
	{
	$ccEmail = cleanPosUrl($_POST['posEmail']);
	@mail($ccEmail,$subject,$message,"From: Yourself <".$ccEmail.">\r\nTo: Yourself");
	}

echo '
	<status>'.$posStatus.'</status>
	<confirmation>'.$posConfirmation.'</confirmation>
	<regarding>'.cleanPosUrl($_POST['posRegard']).'</regarding>
	';
}
echo'	</resultset>';

?>

 

The form also calls these .js files which are ajax

 

contact.js

 

function validateFields() {
var frmEl = document.getElementById('cForm');
var posName = document.getElementById('posName');
var posPhone = document.getElementById('posPhone');
var posEmail = document.getElementById('posEmail');
var posRegard = document.getElementById('posRegard');
var posText = document.getElementById('posText');
var strCC = document.getElementById('selfCC');
var whiteSpace = /^[\s]+$/;
if ( posText.value == '' || whiteSpace.test(posText.value) ) {
	alert("You're trying to send an Empty Email. Please type something and then get on your way.");
}
else if ( posEmail.value == '' && strCC.checked == true ) {
	alert("Why are you trying to CC yourself without an email?");
	alert("Just for that...");
	alert("I\'m Clearing all the fields!");
	frmEl.reset();
	alert("There. Satisified.");
	alert("Now start over!");
	posName.focus();
}
else {
	sendPosEmail();
}
}
function sendPosEmail () {
var success = document.getElementById('emailSuccess');
var posName = document.getElementById('posName');
var posPhone = document.getElementById('posPhone');
var posEmail = document.getElementById('posEmail');
var posRegard = document.getElementById('posRegard');
var posText = document.getElementById('posText');
var strCC = document.getElementById('selfCC').value;
var page = "scripts/xmlHttpRequest.php?contact=true&xml=true";

showContactTimer(); // quickly begin the load bar
success.style.display = 'none'; // hide the success bar (incase this is a multi-email

// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.
var str1 = posName.value;
str1 = str1.replace(/&/g,"**am**");
str1 = str1.replace(/=/g,"**eq**");
str1 = str1.replace(/\+/g,"**pl**");
var str2 = posEmail.value;
str2 = str2.replace(/&/g,"**am**");
str2 = str2.replace(/=/g,"**eq**");
str2 = str2.replace(/\+/g,"**pl**");
var str3 = posRegard.value;
str3 = str3.replace(/&/g,"**am**");
str3 = str3.replace(/=/g,"**eq**");
str3 = str3.replace(/\+/g,"**pl**");
var str4 = posText.value;
str4 = str4.replace(/&/g,"**am**");
str4 = str4.replace(/=/g,"**eq**");
str4 = str4.replace(/\+/g,"**pl**");

var stuff = "selfCC="+strCC+"&posName="+str1+"&posEmail="+str2+"&posRegard="+str3+"&posText="+str4;
loadXMLPosDoc(page,stuff)
}
function showContactTimer () {
var loader = document.getElementById('loadBar');
loader.style.display = 'block';
sentTimer = setTimeout("hideContactTimer()",6000);
}

function hideContactTimer () {
var loader = document.getElementById('loadBar');
var success = document.getElementById('emailSuccess');
var fieldArea = document.getElementById('contactFormArea');
var inputs = fieldArea.getElementsByTagName('input');
var inputsLen = inputs.length;
var tAreas = fieldArea.getElementsByTagName('textarea');
var tAreasLen = tAreas.length;
// Hide the load bar alas! Done Loading
loader.style.display = "none";
success.style.display = "block";
success.innerHTML = '<strong style="color:green;">'+grabPosXML("confirmation")+'</strong>';
// Now Hijack the form elements
for ( i=0;i<inputsLen;i++ ) {
	if ( inputs[i].getAttribute('type') == 'text' ) {
		inputs[i].value = '';
	}
}
for ( j=0;j<tAreasLen;j++ ) {
	tAreas[j].value = '';
}
}

function ajaxContact() {
var frmEl = document.getElementById('cForm');
addEvent(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEvent(window, 'load',ajaxContact, false);

 

functionAddevents.js

function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) { 
elm.addEventListener(evType, fn, useCapture); 
return true; 
}
else if (elm.attachEvent) { 
var r = elm.attachEvent('on' + evType, fn); 
EventCache.add(elm, evType, fn);
return r; 
}
else {
elm['on' + evType] = fn;
}
}
function getEventSrc(e) {
if (!e) e = window.event;

if (e.originalTarget)
return e.originalTarget;
else if (e.srcElement)
return e.srcElement;
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = 
	function() {
	oldonload();
	func();
	}
}
}
var EventCache = function(){
var listEvents = [];
return {
	listEvents : listEvents,

	add : function(node, sEventName, fHandler, bCapture){
		listEvents.push(arguments);
	},

	flush : function(){
		var i, item;
		for(i = listEvents.length - 1; i >= 0; i = i - 1){
			item = listEvents[i];

			if(item[0].removeEventListener){
				item[0].removeEventListener(item[1], item[2], item[3]);
			};

			/* From this point on we need the event names to be prefixed with 'on" */
			if(item[1].substring(0, 2) != "on"){
				item[1] = "on" + item[1];
			};

			if(item[0].detachEvent){
				item[0].detachEvent(item[1], item[2]);
			};

			item[0][item[1]] = null;
		};
	}
};
}();


addEvent(window,'unload',EventCache.flush, false);

 

and finally

 

xmlhttp.js

 

var pos; // variable for posting information
function loadXMLPosDoc(url,posData) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        pos = new XMLHttpRequest();
        pos.onreadystatechange = processPosChange;
        pos.open("POST", url, false);
	pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        pos.send(posData);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        pos = new ActiveXObject("Microsoft.XMLHTTP");
        if (pos) {
            pos.onreadystatechange = processPosChange;
            pos.open("POST", url, false);
		pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            pos.send(posData);
        }
    }
}

function grabPosXML (tagName) {
return pos.responseXML.documentElement.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
}

function processPosChange() {
    // page loaded "complete"
    if (pos.readyState == 4) {
        // page is "OK"
        if (pos.status == 200) {
		if ( grabPosXML("posStatus") == 'NOTOK' ) { 
			alert('There were problems Sending Email. Please check back in a couple minutes');
		}
	}
}
}

 

Thanks for taking the time to have a look, i reliase its a lot of code!

 

 

 

 

Link to comment
Share on other sites

Yes it is a lot of code and I doubt anyone is going to read through all of that. You need to take some time and perform some debugging to narrow down the problem. If you have verified that the POST data is received there is no reason to continue analyzing the form. Here are some things to test/verify:

 

Verify the POST data is received by the processing page.

 

Have you checked the spam folder for the email account you are sending to?

 

Echo the mail() variables ($to,$subject,$message,$headers) to the page to ensure they are what you expect. If so, then you know everything is ok up till that point. This is probably the most important piece of information. If the variables aren't what they should be, then you need to trace back to the source of the problem.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.