Log in

View Full Version : Contact form help



Meanies
27-02-2012, 08:17 PM
Okay it's been ages since I've done anything websitey and I'm getting really frustrated. When the submit button is pressed, it takes you to the php file and doesn't send the email. The codes I have are these;

HTML file

<div class="article">
<h2>Contact me?</h2>
<form action="contact.php" method="POST">
<div class="cl"></div>
<div class="column-cnt">
<div class="cl"></div>
<div class="column">
<label for="your-name">Your Name?</label>
<span class="text-field"><input type="text" id="your-name" value="" /> </span>
</div>
<div class="column">
<label for="your-email">Your E-mail address?</label>
<span class="text-field"><input type="text" id="your-email" value="" /></span>
</div>
<div class="cl"></div>
<p>little bit of writing</p>
</div>
<div class="column-big">
<label for="your-message">Your Message</label>
<span class="text-area"><textarea id="your-message" rows="" cols=""></textarea> </span>
<a href="#">Send the message</a>
<input type="submit" value="Send">
</div>
<div class="cl"></div>
</form>
</div>

PHP file

<?php
$field_name = $_POST['your-name'];
$field_email = $_POST['your-email'];
$field_message = $_POST['your-message'];

$mail_to = 'notseeingmyemail';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact_page.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed.');
window.location = 'contact_page.html';
</script>
<?php
}
?>

Chippiewill
27-02-2012, 08:19 PM
Is email properly set up on the server you're using?

Lee
27-02-2012, 08:29 PM
I can't see any problems with your code, so you should double check your server settings and info.

Meanies
27-02-2012, 08:42 PM
Okay I made a silly mistake and completely forgot I was working through xampp and not actually online so that is rather awkward.

On submission, how can I take the user back to the page they were on? Or even just back to the homepage to keep it simple?

Lee
27-02-2012, 09:06 PM
use the header.


<?php
$field_name=$_POST['your-name'];
$field_email=$_POST['your-email'];
$field_message=$_POST['your-message'];

$mail_to='notseeingmyemail';
$subject='Messagefromasitevisitor'.$field_name;

$body_message='From:'.$field_name."\n";
$body_message.='E-mail:'.$field_email."\n";
$body_message.='Message:'.$field_message;

$headers='From:'.$field_email."\r\n";
$headers.='Reply-To:'.$field_email."\r\n";

$mail_status=mail($mail_to,$subject,$body_message, $headers);

if($mail_status){?>
<scriptlanguage="javascript"type="text/javascript">
alert('Thankyouforthemessage.Wewillcontactyoushort ly.');
window.location='contact_page.html';
</script>
<?php
header('Location: ./index.php');}
else{?>
<scriptlanguage="javascript"type="text/javascript">
alert('Messagefailed.');
window.location='contact_page.html';
</script>
<?php
}
?>

Twista500
06-03-2012, 10:42 PM
If your having problems with the code Just Search google For free Contact us forms etc, You can build it yourself then you get the HTML you get emails from it

Want to hide these adverts? Register an account for free!