Page 1 of 1

PHP Mail form issue

Posted: Wed Jun 22, 2011 9:05 am
by james595832
Hi everyone got a slight problem with this form. It started out as a small contact form script but I wanted to expand it to be larger and contain more fields. Currently isn't working and can't think why:

Here is the two pieces of code

referralform.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>

</head>

<body>
<div id="argentotoplogo"><a href="http://www.argento.co.uk"><img src="../argentologogrey.png" alt="Argento.co.uk" width="200" height="100" border="0" /></a></div>
<div id="maincontent">
<div id="contentform"><form action="/mailer.php" method="post" name="form1" id="form1" style="margin:0px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:300px;" onsubmit="MM_validateForm('from','','RisEmail','subject','','R','verif_box','','R','message','','R');return document.MM_returnValue">
Your e-mail:<br />
<input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['from'];?>"/>
<br />
<br />
Subject:<br />
<input name="subject" type="text" id="subject" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['subject'];?>"/>
<br />
<br />
Customer Name:<br />
<input name="CustomerName" type="text" id="customername" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['customername'];?>"/>
<br />
<br />
Customer Address:<br />
<input name="CustomerAddress" type="text" id="customeraddress" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['customeraddress'];?>"/>
<br />
<br />
Customer Postcode:<br />
<input name="CustomerPostcode" type="text" id="customerpostcode" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['customerpostcode'];?>"/>
<br />
<br />
Customer Account Number:<br />
<input name="customeraccount" type="text" id="customeraccount" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['customeraccount'];?>"/>
<br />
<br />
Item Required (Include price + Pos Code):<br />
<input name="itemrequired" type="text" id="itemrequired" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['itemrequired'];?>"/>
<br />
<br />
Additonal Products Required:<br />
<input name="addproducts" type="text" id="addproducts" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['addproducts'];?>"/>
<br />
<br />
Customer Phone Number:<br />
<input name="phonenumber" type="text" id="phonenumber" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['phonenumber'];?>"/>
<br />
<br />
Best Time To Call (Before 5pm):<br />
<input name="bestcalltime" type="text" id="bestcalltime" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['bestcalltime'];?>"/>
<!-- if the variable "wrong_code" is sent from previous page then display the error field --><br />
<?php ;}?>
<br />
Other Notes
<br />
<textarea name="message" cols="6" rows="5" id="message" style="padding:2px; border:1px solid #CCCCCC; width:300px; height:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"><?php echo $_GET['message'];?></textarea>
<noscript><a href="http://www.thewebhelp.com" style="display:none;">contact form by thewebhelp</a></noscript>
<input name="Submit" type="submit" style="margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;" value="Send Message"/>
</form></div>

</div>
</body>
</html>


Then when you click submit in should go to this coded page :

<?php
// -----------------------------------------
// PHP Referral Email for the AG staff
// -----------------------------------------


// load the variables form address bar
$subject = $_POST["subject"];
$message = $_POST["message"];
$from = $_POST["from"];
$customername = $_POST["customername"];
$customeraddress = $_POST["customeraddress"];
$customerpostcode = $_POST["customerpostcode"];
$customeraccount = $_POST["customeraccount"];
$itemrequired = $_POST["itemrequired"];
$addproducts = $_POST["addproducts"];
$phonenumber = $_POST["phonenumber"];
$bestcalltime = $_POST["bestcalltime"];

// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$from = stripslashes($from);
$customername = stripslashes($customername);
$customeraddress = stripslashes($customeraddress);
$customerpostcode = stripslashes($customerpostcode);
$customeraccount = stripslashes($customeraccount);
$itemrequired = stripslashes($itemrequired);
$addproducts = stripslashes($addproducts);
$phonenumber = stripslashes($phonenumber);
$bestcalltime = stripslashes($bestcalltime);

// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
mail("referrals@argento.co.uk", 'Argento Contact Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else if(isset($message) and $message!=""){
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
} else {
echo "no variables received, this page cannot be accessed directly";
exit;
}
?>
<style type="text/css">
#maincontent {
position:absolute;
width:680px;
height:400px;
left:340px;
top: 100px;
background-image:url(http://www.argentoblog.co.uk/catalogue/680x400.jpg);
background-repeat:no-repeat;
}
#contentform {
position:absolute;
width:382px;
height:344px;
left:18px;
top: 37px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
#argentologo {
}
#maincontent #contentform p a {
color: #3694BA;
}
#argentotoplogo {
position:absolute;
width:200px;
height:100px;
left:340px;
top: 2px;
}
#footerbanner { position:absolute;
width:680px;
height:107px;
left:340px;
top: 508px;
}
#returnlink {
position:absolute;
width:142px;
height:18px;
left:880px;
top: 77px;
color:#666;
}
#returnlink a {
color: #5e5e5e;
font-family: Verdana, Geneva, sans-serif;
font-size: 10px;
}
#webstrapline {
position:absolute;
width:200px;
height:101px;
left:830px;
top: 615px;
}
</style>
</head>

<body>
<div id="maincontent">
<div id="contentform">
<div id="argentologo">
<p><img src="../argentologo.png" width="200" height="100" alt="Argento"></p>
<p>Thank you for your enquiry. Customer Services will now process your request.</p>
<p>If you need any help contact 0845 366 4224 <br>
<a href="http://www.argento.co.uk"><br>
</a></p>
</div>
</div>


</div>
<div id="argentotoplogo"><a href="http://www.argento.co.uk"><img src="../argentologogrey.png" alt="Argento.co.uk" width="200" height="100" border="0"></a></div>
<div id="footerbanner"><a href="http://asp-gb.secure-zone.net/v2/index. ... g=en"><img src="../footerbanner.JPG" alt="Argento Spring Catalogue" width="680" height="107" border="0" /></a></div>
</body>
</html>

Re: PHP Mail form issue

Posted: Wed Jun 22, 2011 9:12 am
by Apollo

Re: PHP Mail form issue

Posted: Wed Jun 22, 2011 9:28 am
by james595832
good man will code it out following the rules.

Re: PHP Mail form issue

Posted: Wed Jun 22, 2011 10:45 am
by social_experiment
If you could also elaborate a bit more on what type of error message you are receiving (if any) that will also increase chances of getting the problem solved a lot quicker. :)