PDA

View Full Version : Problem with Contact Form - Won't link textfields


jamieee0810
01-27-2015, 06:42 AM
Hi All I'm hoping someone can help me out with this problem that I've been staring at for two days now and I can't seem to figure it out even with countless tutorials and forums! Basically I'm new to Dreamweaver but am having a go at building myself a website - rather than try doing it from scratch I figured I'd get a template from the web and edit it. Now there already existed in the template a contact form but no PHP file to get it to send and the button that was created had no actions on it. I got a tutorial on how to put together the PHP file and renamed the text fields to how they exist in the template and added the action to the button which only half works - the email sends but it doesn't link what's in the text boxes so I pretty much get a blank email (except for the small bits that are hard coded in. The html for the form is as follows:

<form action="RoyleData.php" method="post" name="Contact" id="Contact">
<div class="form-group">
<input name="fullname" type="text" class="form-control" id="fullname" placeholder="Your Name" maxlength="30">
</div>
<div class="form-group"></div>
<div class="form-group">
<p>
<input name="email" type="text" class="form-control" id="email" placeholder="Your Email" maxlength="30">
</p>
</div>
<div><button type="button" class="btn btn-primary" onClick="MM_validateForm('fullname','','R','email','','RisE mail','message','','R');MM_goToURL('parent','Royle Data.php');return document.MM_returnValue">Send Message</button></div>


<div class="col-md-9">
<div class="txtarea">
<textarea name="message" rows="10" class="form-control" id="message"></textarea>
</form>

and the PHP file...

<?php

/* Email Variables */
$emailSubject = 'RoyleData'; /*Make sure this matches the name of your file*/
$webMaster = 'jamie@royledata.com';

/*design by Mark Leroy @ http://www.helpvid.net*/

/* Data Variables */
$email = $_POST['email'];
$name = $_POST['fullname'];
$comments = $_POST['message'];



$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Comments: $comments <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);


/* Results rendered as HTML */
$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="3;URL=http://www.royledata.com">
<style type="text/css">
<!--
body {
background-color: #444; /* You can edit this CSS to match your website*/
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #fec001;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}
-->
</style>
</head>
<div align="center">Thank-you for your enquiry, I will be in touch very soon.</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>

I would appreciate any help with this - I'm sure the answer is simple but it is just escaping me!!

edbr
01-27-2015, 07:34 AM
as you didnt show your validation i took it out changed the button and it sent all with data
<form action="RoyleData.php" method="post" name="Contact" id="Contact">
<div class="form-group">
<input name="fullname" type="text" id="fullname" placeholder="Your Name" maxlength="30">
</div>
<div class="form-group"></div>
<div class="form-group">
<p>
<input name="email" type="text" vid="email" placeholder="Your Email" maxlength="30">
</p>
</div>
<div><input name="" type="submit" value="Submit"></div>


<div class="col-md-9">
<div class="txtarea">
<textarea name="message" rows="10" id="message"></textarea>
</form>

edbr
01-27-2015, 07:38 AM
a really easy form (javascript) validator is at http://formvalidator.net/

jamieee0810
01-27-2015, 08:29 AM
Thank-you I really appreciate you taking the time to help me with this - I'll try it when I get home and let you know how I get on. :-)

jamieee0810
01-27-2015, 08:21 PM
That worked perfectly thank-you so much. With a bit of jiggery-pokery I was able to get it to look the same. :smile:

jamieee0810
01-28-2015, 08:33 AM
Further to this upon testing it, it appears to work intermittently. I don't seem to get the emails whenever I put an actual email address in the email box. Presumably this issue is in the PHP script - is there anything you can see that might be causing this.

To explain a little more if I put "TEST" in the email field I get the complete email from TEST@hosts.co.uk, if I put XYZ@hotmail.com I don't get an email at all. I guess this could also be an issue with the host itself?

edbr
01-28-2015, 08:53 AM
sounds like it could be a validation issue

jamieee0810
01-28-2015, 05:53 PM
OK for anybody else that might come across this issue (the helpvid tutorial on contact forms and the php script provided seems pretty widely used) I managed to get past the issue by slightly amending the php script.

The issue was in this part:

$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Comments: $comments <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);

In particular the "From: $email\r\n", instead of calling the email textbox from the contact form as the sender I changed it to something generic i.e. swap '$email' with 'xyz'. I assume there is an issue with receiving an email from 'xyz@xzy.com@hosts.co.uk' however I would not like to speculate because I simply don't know.

Thanks again for your help edbr.