How to create a html contact form. Copy and paste and jobs a goodun.

This does include validation (if by that you mean it checks the details entered are allowed)
validation is necessary server side to be used as a safety mechanism.
If you just want extra usability validation, javascript client side is a good idea too.
 
Yes it does server side Glen.
Try it out and you will see, notice any problems with it let me know. : )
 
No I think it reads okay:

Contact form a respectful bow made by women of Jazajay at designforums.co.uk

To be honest. :D

Cheers I'll get round to editing it. :)
 
Thread resurrection!

Is there away to get it to put the sender's email address in as the 'sending' email so it can be replied to by the recipient?

At the moment all I get is sent by CGI-Mailer, so in order to reply one has to copy and paste the email address.

I've used a similar form elsewhere, but nowhere near as good or well written (I bastardised it) which uses $EmailFrom = $_REQUEST['Email']; to achieve the same thing. However I can't get it or something of that ilk to work in this form.
 
Becky said:
Thread resurrection!

Is there away to get it to put the sender's email address in as the 'sending' email so it can be replied to by the recipient?

At the moment all I get is sent by CGI-Mailer, so in order to reply one has to copy and paste the email address.

I've used a similar form elsewhere, but nowhere near as good or well written (I bastardised it) which uses $EmailFrom = $_REQUEST['Email']; to achieve the same thing. However I can't get it or something of that ilk to work in this form.


random bump :confused:

Would really love it if the emails came in addressed from the sender and not cgi mailer :(
 
Had the same issue, had some help from Jaz when I was trying to write the below (I'm a php newbie :p)

It wouldn't use the sender's email addy but after a lot of tinkering got it to work :)

Code:
<?php$ip = $_SERVER['REMOTE_ADDR'];$subject = "Message from Website";$name = $_POST['name'] ;$address = $_POST['address'] ;$postcode = $_POST['postcode'] ;$dayno = $_POST['dayno'] ;$faxno = $_POST['faxno'] ;$email = $_POST['email'] ;$query = $_POST['query'] ;$other = $_POST['other'] ;$requirements = $_POST['requirements'] ;$approxsize = $_POST['approxsize'] ;$extras = $_POST['extras'] ;$comments = $_POST['comments'] ;$budget = $_POST['budget'] ;$output = "Message from Contact Form \n\nSubmitted From: $ip \n\nQuery Type: $query \nOther: $other \n\nName: $name \nDaytime Number: $dayno \nFax Number: $faxno \nEmail Address: $email \n\nAddress:\n $address  \nPostcode: $postcode \n\nComments:\n $comments \n\nRequirements:\n $requirements \n\nApproximate Size: \n $approxsize \n\nExtras:\n $extras  \n\nBudget: $budget" ;$headers .= 'MIME-Version: 1.0' ;$mailto = "add in email address here"."\r\n";$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;$headers .= 'Reply-To: $mailfrom' ."\r\n" ;$headers = "From: $email"; mail ($mailto, $subject, $output, $headers);header( "Location: /success.html" );?>
Put the whole form up for easy reading lol

Hope that helps, it's accessed from a html page and works fine with a javascript form checker :)
 
Hay Becky yeah sorry read your post then forgot all about it.
This should be what your after. What the changes do is they put the header of the message, who it's from, currently as your site. That way you know it's a message from your site. If you then click reply it replies to the email address they added. I've just quickly tested this and it appears to work fine, but if you run in to any issues let me know. Going to make 100% sure after I get back from my sons first school sports day and i'll make it the next version.

The change is in bold half way down. I'll re-edit this post when I get back to make all the areas that need changing more clearer. Any problems you do notice let me know.

To save you having to change everything again, you can just copy and paste that line into your current file at the same position and change Your site to whatever you want. :)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Contact us</title>
<style type="text/css">
#success h1{color:green}
#error h2{color:red}
#feedback{
position:absolute;
margin:-560px 0 0 450px;
width:400px;
height:200px;
padding:0 10px 10px;
-moz-box-shadow:1px 2px 5px #666;
-webkit-box-shadow:1px 2px 5px #666;
border:1px solid #CCC;
background:#FFF
}
#feedback,x:-webkit-any-link{margin-top:-600px}
#feedback,x:-moz-any-link{margin-top:-600px}
</style>
<!--[if IE]>
<style type="text/css">
#feedback{
margin-top:-580px;
height:180px
}
</style>
<![endif]-->
<!--[if IE 6]>
<style type="text/css">
#feedback{
margin-top:-600px;
padding-top:10px;
height:190px
}
</style>
<![endif]-->
</head>
<body>
<?php if(!isset($_POST['name'])){?>
<h1>Contact us</h1>
<?php }
if(isset($_POST['name']))
{
$count=0;
$err="<h2>Please fix the errors below to be able to contact me: </h2>";
if(!empty($_POST["name"])){
$from = $_POST["name"];
}else{
$count++;
$err.="~ Please enter your name<br />";
} if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$count++;
$err.="~ Your email address appears to be wrong,<br />";
}
}else{
$count++;
$err.="~ You need to enter an email address so I can contact you<br />";
} if(!empty($_POST['mess'])){
$content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";
$content = $content . $_POST["mess"];
$content = strip_tags(wordwrap($content, 70));
}else{
$count++;
$err.="~ Your message was blank";
}
if($count==0){
$to="[email protected]";
$subject="Message from ".strip_tags($_POST['name']);
$headers='MIME-Version: 1.0' . "\r\n";
$headers.='Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers.="From: Your Site <".$email.">"."\r\n";
if(!empty($_POST['email'])){$email="<p>Email: ".strip_tags($_POST['email'])."</p>";}
$body="<p>From: ".strip_tags($_POST['name'])."</p><p>Email:".strip_tags($_POST["email"])."</p><p>".strip_tags($_POST['mess'])."</p>";
mail($to,$subject,$body,$headers);
//Change the email address you want it to be sent to, this goes in the $to variable inside the quotes in the in the bolded statement above and the Your site to your site's name in the from section of the $headers variable.
?>
<div id="success">
<h1>Success</h1>
<p>
Your message has been sent and I always aim to reply to all emails within 48hours.
</p>
<p>
Thank you for taking the time to contact me.
</p>
<p>
<i>Add your name or company name in here.</i>
<!-- Add your name here-->
</p>
<p>
<a href="http://#">Back to our home page</a>
<!-- Add your domain name in between the quote marks ie http://www.yoursite.com/-->
</p>
</div>
<?php }else{?>
<div id="error">
<h1><?php if($count>1){echo $count;?> errors <?php }else{?>1 error <?php }?>occured when trying to contact me</h1>
<form method="post" action="">
<p><label for="name">Name: </label></p>
<p>
<input type="text" name="name" id="name"<?php if(!empty($_POST["name"])){?> value="<?php echo $_POST['name'];?>"<?php }?> />
</p>
<p><label for="email">Email: </label></p>
<p>
<input type="text" name="email" id="email"<?php if(!empty($_POST["email"])){?> value="<?php echo $_POST['email'];?>"<?php }?> />
</p>
<p><label for="message">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="message"><?php if(!empty($_POST["mess"])){?><?php echo $_POST['mess'];}?></textarea>
</p>
<p><button type="submit">Contact me</button></p>
</form>
<div id="feedback">
<?php echo $err;?>
</div>
</div>
<?php }
}else{
?>
<form method="post" action="">
<p><label for="name">Name: </label></p>
<p>
<input type="text" name="name" id="name" />
</p>
<p><label for="email">Email: </label></p>
<p>
<input type="text" name="email" id="email" />
</p>
<p><label for="message">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="message"></textarea>
</p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }?>
<!--Contact form courtesy of Jazajay at designforums.co.uk-->
</body>
</html>
 
@ Jazajay

Easy now I cant wait to test this bad boy, I tried to make a form from scratch the other day but after it kept falling over I couldnt be ***** to step through it... yes I dont particularly like coding!
 
No worries any issues you run in to just give me a shout, test it in Safari for the best results.
Jaz :)
 
Hey,

Please forgive me for being well 'stupid' but i am new to web design and i have taken your code and changed the bits as instructed.

I have saved to .php, it is new to me uploading to get it to work on my site.

I know how to upload my .html files onto my server but i am not sure about .php, it is a little confusing to me.

Any help guys:)???

Thanks,

Sam
 
Hmmm,

Maybe i need to employ you becky:p

So i use filezilla for example, i still uplaod as per usual, atm i am uploading both the contact.html and contact.php is this correct?

As it doesnt appear to be recognising the php

Sam:)
 
no, you only need to upload the .php the php file is a replacement for the html in order to use the coding within it.
 
Thanks Becky i was having a blonde moment and it was still trying to direct it to contact.html from my homepage. My bad,

Just loaded it, is this a standalone form or is there any easy way of incoporating it into my design?

Tell me to **** off if you like :)
 
Its okay now i have managed it:) a complete guess but non the less it worked.

This forum is really useful and i didnt realise how many people are members, 2500+ wow!

Thanks Becky:)

Sam
 
Back
Top