Hey,
Just wondering if anyone can help me. I’m trying to get my contact form to post to my email, and also send a receipt type email to the person who filled it out. I also want them to be directed to thankyou.php after filling it out.
I’ve coded and styled my form. Below is the html…
<div class="form">
<!-- Form Code Start -->
<form class="contactForm" method="post" action="mailer.php">
<fieldset>
<div class="details details-left">
<label for="Name">Name *</label>
<input class="validate[required,length[0,100]] text-input" type="text" name="Name" id="Name" />
</div>
<div class="details">
<label for="Email">Email *</label>
<input class="validate[required,custom[email]] text-input" type="email" name="Email" id="Email"/>
</div>
<div class="details details-left">
<label for="Phone">Phone *</label>
<input class="validate[required,custom[telephone]] text-input" type="text" name="Telephone" id="Telephone" />
</div>
<div class="details">
<label for="message-title">Message Title:</label>
<input type="text" name="subject" id="subject" />
</div>
</fieldset>
<fieldset>
<div class="message">
<label for="message">Message:</label>
<textarea rows="10" cols="50" class="validate[required,length[1,1000]] text-input" name="Enquiry" id="Enquiry"></textarea>
</div>
</fieldset>
<fieldset>
<input class="submit" name="submit_contact_form" type="submit" value="Submit"/>
</fieldset>
</form>
</div>
If anyone could help, that’d be great!
Ok, I’ve got it to post to my email using the script below…
<?php
if(isset($_POST['submit']))
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Telephone = $_POST['Telephone'];
$Enquiry = $_POST['Enquiry'];
$to = "info@example.com"; // <<< change this to your own E-mail address
$subject = "Website - Enquiry";
$msg = "Name: $Name\
" . "Email: $Email\
" . "Telephone: $Telephone\
" . "Message: $Enquiry";
$headers = "From: $Email" . "\\r\
" .
"Reply-To: $Email" . "\\r\
" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $msg, $headers);
echo "Thank you for contacting us! Please allow 48 hours for a representative to respond. Click <a href='contact.php'>here</a> to return to the previous page.";
?>
Is there any way of getting it redirect to a thank you page?
Make the redirect after all is done
<?php
// ....
header('Location: thankyou.php');
exit;
Rubble
April 14, 2014, 8:34am
4
Make sure you replace this:
echo "Thank you for contacting us! Please allow 48 hours for a representative to respond. Click <a href='contact.php'>here</a> to return to the previous page.";
With:
header('Location: thankyou.php');
exit;
As you can not have any html output before the header()
ralphm
April 14, 2014, 9:52am
6
also send a receipt type email to the person who filled it out.
This part wasn’t covered in the answers, but that’s easy, too. You could add the code in red:
<?php
if(isset($_POST['submit']))
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Telephone = $_POST['Telephone'];
$Enquiry = $_POST['Enquiry'];
$to = "info@example.com"; // <<< change this to your own E-mail address
$subject = "Website - Enquiry";
$msg = "Name: $Name\
" . "Email: $Email\
" . "Telephone: $Telephone\
" . "Message: $Enquiry";
[COLOR="#FF0000"]$subject2 = "Thanks for your message";
$msg2 = "Thank you for contacting us! Please allow 48 hours for a representative to respond.";[/COLOR]
$headers = "From: $Email" . "\\r\
" .
"Reply-To: $Email" . "\\r\
" .
"X-Mailer: PHP/" . phpversion();
[COLOR="#FF0000"]$headers2 = "From: info@example.com" . "\\r\
" .
"Reply-To: info@example.com" . "\\r\
" .
"X-Mailer: PHP/" . phpversion();[/COLOR]
mail($to, $subject, $msg, $headers);
[COLOR="#FF0000"]mail($Email, $subject2, $msg2, $headers2);[/COLOR]
header('Location: thankyou.php');
exit;
?>
(There are other ways to do it, and I’m not a PHP guy, but that will work.)
Thank you! Will give this a try tonight
ralphm
April 15, 2014, 8:48am
9
beckybrammers:
It worked! Thank you
That’s great. Glad to hear it.
<?php
if(isset($_POST['submit']))
extract($_POST);
$to = "info@example.com"; // your email here
$subject = "Enquiry from Website";
$msg = "Name: $Name\
" . "Email: $Email\
" . "Telephone: $Telephone\
" . "Message: $Enquiry";
$headers = "From: $Email";
mail($to, $subject, $msg, $headers);
echo "Thank you for contacting us! Please allow 48 hours for a representative to respond. Click <a href='contact.php'>here</a> to return to the previous page.";
else
echo "you male not send sucessfully";
?>
Happy to help you…