php contact form, help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
enricia
Forum Newbie
Posts: 2
Joined: Tue Sep 22, 2009 9:57 am

php contact form, help

Post by enricia »

hello,
I have created php contact form and it doesn't work. I tried to change it and it still shows error on page. I will paste the of the 2 files here and if anyone wil help me would be great. thanks for any informations :)

contact.php:

<?php


$to = "myemail@yahoo.co.uk";
$subject_prefix = "";

if(!isset($_GET['action']))
{
die("You must not access this page directly!");
}


$fleet number = trim($_GET['fleet number']);
$date = trim($_GET['date']);
$name = trim($_GET['name']);
$reported = trim($_GET['reported']);
$address = trim($_GET['address']);
$number = trim($_GET['number']);
$defect = trim($_GET['defect']);
$email = trim($_GET['email']);
$subject = trim($_GET['subject']);
$message = trim($_GET['msg']);

mail($to,$fleet number,$date,$reported,$address,$number,$defect,$subject,$message,"From: ".$email."");

echo 'contactarea|Thank you '.$name.', your email has been sent.';
?>

defectform.php:
<html lang="en-gb">
<head>
<title><?php echo $browsertitle; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="robots" content="index,follow">
<meta http-equiv="Pragma" content="no-cache">
<meta name="author" content="www.nevada.ie">
</head>
<body onLoad="MM_preloadImages('/imgs/buttons/profile.on.gif','/imgs/buttons/why.on.gif','/imgs/buttons/home.on.gif','/imgs/buttons/product.on.gif','/imgs/buttons/news.on.gif')">
<table width="774" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="bg">
<tr>
<td valign="top">
<table width="774" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<?php include("inc/header.php") ?>
</td>
</tr>
<tr>
<td><table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="/index.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','/imgs/buttons/home.on.gif',1)"><img src="/imgs/buttons/home.off.gif" alt="Home" name="home" width="74" height="47" border="0"></a></td>
<td><a href="/gritters.ploughs.snow.clearing.ice.treatment.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('product','','/imgs/buttons/product.on.gif',1)"><img src="/imgs/buttons/product.off.gif" alt="Product Range" name="product" width="89" height="47" border="0"></a></td>
<td><a href="/gritters.and.ploughs.romaquip.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('profile','','/imgs/buttons/profile.on.gif',1)"><img src="/imgs/buttons/profile.off.gif" alt="Company Profile" name="profile" width="96" height="47" border="0"></a></td>
<td><a href="/winter.gritting.snow.clearing.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('why','','/imgs/buttons/why.on.gif',1)"><img src="/imgs/buttons/why.off.gif" alt="Why Romaquip?" name="why" width="104" height="47" border="0"></a></td>
<td><a href="/romaquip.news.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('news','','/imgs/buttons/news.on.gif',1)"><img src="/imgs/buttons/news.off.gif" alt="News" name="news" width="67" height="47" border="0"></a></td>
<td><img src="/imgs/buttons/contact.on.gif" alt="Contact Us" name="contact" width="105" height="47" border="0"></td>
<td><img src="/imgs/sundries/yellow.nav.rectangle.gif" width="225" height="47"></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="742" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="95%" valign="top" class="paddingLeft10px"><table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top" class="marginRight20px"><table width="725" border="0" cellpadding="0" cellspacing="0">
<tr>

</table>
<img src="imgs/titles/defet.gif" alt="DEFECT REPORT FORM" width="725" height="28"> <h1><span class="alignTop">
<p><center><font size="=7" color="#696969"> DEFECT/BREAKDOWN (TO BE COMPLETED BY SERVICE PROVIDER)</font></center></p>

<style type="text/css">

#inputbox{
border: 1px solid #000;
width: 200;
padding: 2px;
font-weight: bold;
font-family: Verdana, Arial;
font-size: 12px;
}
#inputlabel {
font-weight: bold;
font-family: Verdana, Arial;
font-size: 12px;
}
#textarea {
border: 1px solid #000;
padding: 2px;
font-weight: bold;
font-family: Verdana, Arial;
font-size: 12px;width:400;
}
#submitbutton {
border: 1px solid #000;
}
</style>

<script language="javascript">
function createRequestObject()
{
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
ro = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function sendemail()
{
var msg = document.contactform.msg.value;
var fleet number = document.contactform.fleet number.value;
var date = document.contactform.date.value;
var name = document.contactform.name.value;
var reported = document.contactform.reported.value;
var address = document.contactform.address.value;
var number = document.contactform.number.value;
var defect = document.contactform.defect.value;
var email = document.contactform.email.value;
var subject = document.contactform.subject.value;
document.contactform.send.disabled=true;
document.contactform.send.value='Sending....';

http.open('get', 'contact.php?msg='+msg+'&fleet number='+fleet number+'&date='+date+'&name='+name+'&reported='+reported+'&address='+address+'&number='+number+'&defect='+defect+'&email='+email+'&subject='+subject+'&action=send');

http.onreadystatechange = handleResponse;
http.send(null);}

function handleResponse()
{
if(http.readyState == 4)
{
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
} }}

</script>
</head>
<body>
<div id="contactarea">
<form name="contactform" id="contactform">

<span id="inputlabel"> Fleet Number:</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="fleet number" id="inputbox">&nbsp;&nbsp;&nbsp;

<span id="inputlabel">Date:</span> &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="date" id="inputbox"><br /><br />

<span id="inputlabel">Customer Name:</span> &nbsp;
<input type="text" name="name" id="inputbox">
&nbsp;&nbsp;&nbsp;

<span id="inputlabel">Call Reported by:</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="reported" id="inputbox"><br /><br />

<span id="inputlabel"> Depot Address:</span>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="address" id="inputbox">
&nbsp;&nbsp;&nbsp;

<span id="inputlabel">Registration Number:</span>
<input type="text" name="number" id="inputbox"><br /><br />


<span id="inputlabel">Defect Details:</span><br />
<textarea name="defect" rows="3" id="textarea"></textarea>
<br /><br />

<span id="inputlabel">Email:</span> &nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="email" id="inputbox"><br /><br />

<span id="inputlabel">Subject:</span> &nbsp;
<input type="text" name="subject" id="inputbox"><br /><br />

<span id="inputlabel">Message:</span><br />
<textarea name="msg" rows="3" id="textarea"></textarea>
<br /><br />

<input type="button" value="Send Email" name="send" onClick="sendemail();" id="submitbutton">
</form>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center" valign="top"><img src="/imgs/sundries/yellow.footer.bar.gif" width="760" height="3"></td>
</tr>
<tr>
<td align="center" valign="top">
<?php include("inc/footer.htm") ?>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: php contact form, help

Post by Eric! »

Try my example. You can configure it and it will protect you from various email attacks.

viewtopic.php?f=50&t=104240

Also learn how to use

Code: Select all

tags when posting code here.

FYI your call to mail() will never work with that many parmeters, you have to build the message.  See my example.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php contact form, help

Post by jackpf »

mail($to,$fleet number,$date,$reported,$address,$number,$defect,$subject,$message,"From: ".$email."");
That made me l0l.

Read up on mail() and it's arguments here.

And yes...please, do as Eric! requested and use code tags.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: php contact form, help

Post by Mirge »

Image
enricia
Forum Newbie
Posts: 2
Joined: Tue Sep 22, 2009 9:57 am

Re: php contact form, help

Post by enricia »

thanks for replying and the links for code,
i tried to change the mail() but still wouldn't work...i will be grateful if someone would write me how to change that, many thanks:)
Post Reply