Copy link to clipboard
Copied
Wonder if there is anyone out here who can help - I'm really new to website design and going through an incredibly steep learning curve. I'm using Dreamweaver CS4 and have designed a nice form on my website to get feedback from my visitors. I have had a go a draft the codes for a PHP page to get the info on my form emailed through to me. First problem was getting the email to come through but my server has given me a small test PHP file that seems to have sorted that out. What I am struggling with now is how to adapt that "test" php page from my server to take the information clients put into my form, emailed to me. I then need to be able to redirect folk back to the contact page on my website once they've had their acknowledgment email.
I have to be honest and say I really don't know what I am doing but want to learn - I feel I am so close, but just need help with the last little bit. Would really appreciate any help you could give. Thank you in anticipation.
Copy link to clipboard
Copied
Meroe wrote
Wonder if there is anyone out here who can help - I'm really new to website design and going through an incredibly steep learning curve. I'm using Dreamweaver CS4 and have designed a nice form on my website to get feedback from my visitors. I have had a go a draft the codes for a PHP page to get the info on my form emailed through to me. First problem was getting the email to come through but my server has given me a small test PHP file that seems to have sorted that out. What I am struggling with now is how to adapt that "test" php page from my server to take the information clients put into my form, emailed to me. I then need to be able to redirect folk back to the contact page on my website once they've had their acknowledgment email.
I have to be honest and say I really don't know what I am doing but want to learn - I feel I am so close, but just need help with the last little bit. Would really appreciate any help you could give. Thank you in anticipation.
Can you post the test.php code in the forum along with the html code for your form, so we can see what your host has supplied?
Copy link to clipboard
Copied
Here is the form:
<form action="send_form.php" method="post" name="form1" target="_blank" id="form1">
<fieldset>
<legend class="colour"><strong>Personal Information</strong></legend>
<p> <label class="question" for="the_name"> What is your name?</label>
<input type="text" id="the_name" name="the_name" placeholder="Enter your full name." size="50" required autofocus/> </p>
<p> <label class="question" for="the_email"> What is your email address?</label>
<input type ="email" id="the_email" name="the_email" placeholder="Please enter your email" size="50" required/> </p>
<p> </p>
</fieldset>
<fieldset>
<legend class="colour"><strong>Feedback</strong></legend>
<p><span class="question">Please chose the one that best suits your experience:</span><br/>
<input type="radio" id="vote_yes" name="vote" value="yes" checked />
<label for="vote_yes">Yes</label> <br/>
<input type="radio" id="vote_somewhat" name="vote" value="somewhat" checked />
<label for="vote_somewhat">Somewhat</label> <br/>
<input type="radio" id="vote_no" name="vote" value="No" checked />
<label for="vote_no">No</label> </p>
<p> </p>
</fieldset>
<fieldset>
<p>
<label for "choose_scale"><span class="question"><strong>What is your overall impression of the site on a scale of 1 (poor) to 10 (excellent):</strong></span></label>
<input type="number" id="choose_scale" name="choose_scale" min="0" max="10" step="1" value="5"/></p>
<p> </p>
</fieldset>
<fieldset>
<legend class="colour"><strong>Is there anything else you would like to say or ask?</strong></legend>
<p><label for="message"><span class="question">Let us know if you have any comments or suggestions as to how we can improve our site, or for any other queries.</span></label>
<textarea id="message" name="message" rows="7" cols="55">
</textarea></p>
</fieldset>
<div id="buttons">
<input type="submit" value="Click here to submit" /> or
<input type="reset" value="Erase and start again" />
</div>
</form>
Copy link to clipboard
Copied
Below is the php code starting from <!-- PHP CODE --> - copy, paste into new document and save it as - send_form.php
Change info@yourdomain.co.uk to your email address.
if the email goes through successfully it redirects to a success.html page (you have to create that with a message saying "Your email has been sent successfully". If it fails it redirects to a failure.html page (you have to create that with a failure message).
The email only gets sent IF all the form field are filled in which is what this line checks (if you want to allow a field to be empty then dont include it in the line of code)
if(!empty($the_name) || !empty($the_email) || !empty($vote) || !empty($choose_scale) || !empty($message))
There are other things you should do like check for a vaild email address but this will get you off the ground and running hopefully
<!-- PHP CODE -->
<?php
$email_from = "info@yourdomain.co.uk";
$email_to = "info@yourdomain.co.uk";
$subject = "Feedback from website";
$the_name = trim(stripslashes($_POST['the_name']));
$the_email = trim(stripslashes($_POST['the_email']));
$vote = trim(stripslashes($_POST['vote']));
$choose_scale = trim(stripslashes($_POST['choose_scale']));
$message = trim(stripslashes($_POST['message']));
// prepare email body text
$body .= "Name: $the_name\n";
$body .= "Email: $the_email\n";
$body .= "Vote: $vote\n";
$body .= "Scale: $choose_scale\n";
$body .= "Message: $message\n";
// send email
if(!empty($the_name) || !empty($the_email) || !empty($vote) || !empty($choose_scale) || !empty($message)) {
mail($email_to, $subject, $body, "From: <$email_from>");
// redirect to success page
header("Location: success.html");
}
else{
header("Location: failure.html");
}
?>
Below is the form html (I've amended it slightly)
<form action="send_form.php" method="post" name="form1" id="form1">
<fieldset>
<legend class="colour"><strong>Personal Information</strong></legend>
<p> <label class="question" for="the_name"> What is your name?</label>
<input type="text" id="the_name" name="the_name" placeholder="Enter your full name." size="50" required autofocus/> </p>
<p> <label class="question" for="the_email"> What is your email address?</label>
<input type ="email" id="the_email" name="the_email" placeholder="Please enter your email" size="50" required/> </p>
<p> </p>
</fieldset>
<fieldset>
<legend class="colour"><strong>Feedback</strong></legend>
<p><span class="question">Please chose the one that best suits your experience:</span><br/>
<input type="radio" id="vote_yes" name="vote" value="yes" checked />
<label for="vote_yes">Yes</label> <br/>
<input type="radio" id="vote_somewhat" name="vote" value="somewhat" checked />
<label for="vote_somewhat">Somewhat</label> <br/>
<input type="radio" id="vote_no" name="vote" value="No" checked />
<label for="vote_no">No</label> </p>
<p> </p>
</fieldset>
<fieldset>
<p>
<label for="choose_scale"><span class="question"><strong>What is your overall impression of the site on a scale of 1 (poor) to 10 (excellent):</strong></span></label>
<input type="number" id="choose_scale" name="choose_scale" min="0" max="10" step="1" value="5"/></p>
<p> </p>
</fieldset>
<fieldset>
<legend class="colour"><strong>Is there anything else you would like to say or ask?</strong></legend>
<p><label for="message"><span class="question">Let us know if you have any comments or suggestions as to how we can improve our site, or for any other queries.</span></label>
<textarea id="message" name="message" rows="7" cols="55">
</textarea></p>
</fieldset>
<div id="buttons">
<input type="submit" name="submit" value="Click here to submit" /> or
<input type="reset" value="Erase and start again" />
</div>
</form>
Copy link to clipboard
Copied
Thank you for this. I'm now getting a white error screen.
The website cannot display the page | |||
HTTP 500 | |||
Most likely causes:
| |||
What you can try: | |||
| |||
| |||
Copy link to clipboard
Copied
WORKING! WOO HOO! Thank you so much.
Copy link to clipboard
Copied
Thank you - it's working. In my excitement I think I sent a message to myself! Thank you so much, very much appreciated.
Copy link to clipboard
Copied
Meroe wrote
Thank you - it's working. In my excitement I think I sent a message to myself! Thank you so much, very much appreciated.
No problem, glad it's working for you.
Copy link to clipboard
Copied
This question has been answered - post 6 - for anyone looking for similar issues with a feedback form.
Copy link to clipboard
Copied
Forms are difficult for beginners. And complex forms are even more difficult especially if you don't know much about code, programming & security.
My advice is to use a form service like Wufoo. No coding skills required. Then, learn all you can about HTML and PHP code. When you're coding skills and confidence improve, then you can revisit this advanced project.
Web Forms | How It Works | Wufoo
Nancy
Copy link to clipboard
Copied
This is the test page my server provided:
/**********************************************************************
Change the email address. This is where the test email will be sent to.
**********************************************************************/
$email = "NCTPA@talktalk.net"; // Receiving email address
/*******************************
No Changes need to be made below
*******************************/
$headers .= "From: Example <$email>\n";
$headers .= "Reply-To: $email\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-Mailer: PHP / ".phpversion()."\n";
$headers .= "Return-Path: <$email>\n";
$subject = "Archive Feedback";
mail("$email","$subject","This is a test email from your hosting company to ensure your email is working properly. Please disregard this email.", $headers);
echo "Email sent to $email";
?>
Copy link to clipboard
Copied
Evidently, your server supports PHP code. Try working through this 3-part tutorial.
Alt-Web Design & Publishing: Responsive Contact Form with Bootstrap 3.2 and PHP (Part 1)
Nancy