View Full Version : Help getting Contact Form to work

01-25-2012, 09:11 PM
Im making a website from a template that has an html/php contact form. I've seen plenty of tutorials on how to make php forms but they are all different from the code that was included in my template.
Is it just as simple as entering my email in the [ICODE]$your_email = "james@example.com";[ICODE] line of code? and uploading to my server?



if(!$_POST) exit;

$email = $_POST['email'];

//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
if($errors==1) echo $error;
$values = array ('name','email','message');
$required = array('name','email','message');

$your_email = "james@example.com";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
$email_content .= $value.': '.$_POST[$value]."\n";

if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';


<!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">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
// <![CDATA[
var action = $(this).attr('action');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
company: $('#company').val(),
subject: $('#subject').val(),
message: $('#message').val()
$('#contactform #submit').attr('disabled','');
$('#contactform').before('<p class="response">'+data+'</p>');
if(data=='Message sent!') $('#contactform').slideUp();
return false;
// ]]>
<div class="main">
<div class="blok_header">
<div class="header">
<div class="logo"> <a href="index.html"><img src="images/logo.gif" width="139" height="153" border="0" alt="logo" class="one" /></a> </div>
<div class="menu">
<li><a href="index.html"><span>Home</span></a></li>
<li><a href="about.html"><span>About Us</span></a></li>
<li><a href="portfolio.html"><span>Portfolio</span></a></li>
<li><a href="contact.html" class="active"><span>Contact Us</span></a></li>
<div class="clr"></div>
<div class="clr"></div>
<div class="clr"></div>
<div class="header_text_bg">
<div class="header_text">
<div class="header_text_resize">
<div class="search">
<form id="form1" name="form1" method="post" action="">
<input name="q" type="text" class="keywords" id="textfield" maxlength="50" value="Search..." />
<input name="b" type="image" src="images/search.gif" class="button" />
<h2>Your company's welcome message or slogan. Lorem ipsum dolor sit amet, consectur el.<br />
<span>Donec metus lacus, porta id, auctor sit amet, aliquam eu, lacus. Quisque sagittis vulputate orci.</span></h2>
<div class="clr"></div>
<div class="clr"></div>
<div class="body_resize">
<div class="body">
<div class="left">
<h3>Contact Us<br />
<span> Our mission is simple: </span> </h3>
<p><em>&quot;Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.&quot;</em></p>
<p>Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
<p><br />
<form action="contact.php" method="post" id="contactform">
<label for="name">First Name <span class="red">*</span></label>
<input id="name" name="name" class="text" />
<label for="email">Your email <span class="red">*</span></label>
<input id="email" name="email" class="text" />
<label for="company">Company</label>
<input id="company" name="company" class="text" />
<label for="subject">Subject</label>
<input id="subject" name="subject" class="text" />
<label for="message">Message <span class="red">*</span></label>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
<div class="clr"></div>
<div class="right">
<h3>Contact Details<br />
<span> Lorem ipsum dolor sit amet consectetur </span> </h3>
<p><strong>Address</strong>: 1458 Sample Road, Greenvalley<br />
<strong>Telephone</strong>: +123-1234-5678<br />
<strong>FAX</strong>: +458-4578<br />
<strong>Others</strong>: +301 - 0125 - 01258<br />
<strong>E-mail</strong>: mail@yoursitename.com</p>
<h3>Testimonials<br />
<span> Lorem ipsum dolor sit amet</span></h3>
<p><em>“ Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridicu lus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. „<br />
<strong>- John Doe, companyname.com </strong></em></p>
<h3>Social Places<br />
<span> Lorem ipsum dolor sit amet, consectetur adipiscing <br />
elit. Vestibulum eget bibendum tellus. </span></h3>
<img src="images/rss.jpg" alt="picture" width="259" height="25" /></div>
<div class="clr"></div>
<div class="clr"></div>
<div class="clr"></div>
<div class="FBG">
<div class="FBG_resize">
<div class="left">
<p>Code is seo friendly, optimized for getting the top results in the search engines .</p>
<li><a href="#">Overview </a></li>
<li> <a href="#">Another Link </a></li>
<li> <a href="#">Our Company </a></li>
<li> <a href="#">Our Staff </a></li>
<li> <a href="#">Mision Statement </a></li>
<div class="left">
<p>Neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat magna eros eu erat. </p>
<p>Neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. </p>
<p><a href="#">Check Our Works </a></p>
<div class="left">
<p>Neque id cursus faucibus, tortor <br />
neque egestas augue, eu <br />
vulputate magna eros eu erat. </p>
<li><a href="#">Category 1 </a></li>
<li><a href="#">Category 2 </a></li>
<li><a href="#">Category 3 </a></li>
<li><a href="#">Category 4 </a></li>
<li><a href="#">Category 5 </a></li>
<div class="left">
<p>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. </p>
<p><span>support@yoursite.com <br />
+1 (123) 444-5677</span></p>
<p><span>sales@yoursite.com <br />
+1 (123) 444-5678</span></p>
<div class="clr"></div>
<div class="clr"></div>
<div class="footer">
<div class="footer_resize">
<p class="leftt"> Copyright YourSiteName. All Rights Reserved<br />
<a href="#">Home</a> | <a href="#">Contact</a> | <a href="#">RSS</a></p>
<p class="right">(DT) <a href="http://www.dreamtemplate.com"><strong>Website Templates</strong></a></p>
<div class="clr"></div>
<div class="clr"></div>


01-26-2012, 07:32 AM
the $your_email variable will be where the email get's sent to... the recipient...