PDA

View Full Version : Email Form



simonf
11-16-2017, 01:27 PM
Hi

I have a contact form and I know I have a coding error, but I just can't see the error, some fresh eyes would be appreciated...

HTML Code


<form method="post" action="contact.php" onsubmit="return checkform(this);MM_validateForm('fname','','R','email','','phone','','RisEmail');return document.MM_returnValue">
<p>
<label for="fname">Your Full Name</label>
<input type="text" id="fname" name="fullname" placeholder="Your full name...">

<label for="email">Your Email Address</label>
<input type="text" id="email" name="email" placeholder="Your Email Address...">

<label for="phone">Your Mobile/Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="Your contact number...">

<label for="address">Your Full Address & Erf Number if available</label>
<input type="text" id="address" name="address" placeholder="Your Full Address...">

<label for="message">Add some extra information</label>
<input type="text" id="message" name="message" placeholder="Add some more...">

<br />

<input type="submit" name="send" value="Submit">
<input type="reset" value="Reset" /></p>
</form>



PHP Code


<?php
$to = "simon@silvertreeestates.co.za" ;
$from = $_REQUEST['email'] ;
$name = $_REQUEST['fname'] ;
$headers = "From: $from";
$subject = "Silver Tree Website Contact Form";

$fields = array();
$fields{"name"} = "fname";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"address"} = "address";
$fields{"message"} = "message";

$body = "'A visitor to the Silver Tree Estates website has provided the following valuation information and would like to be contacted a.s.a.p :\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: office@silvertreeestates.co.za";
$subject2 = "Silver Tree Estates Contact";
$autoreply = "Thank you for contacting Silver Tree Estates for a Free Valuation!

We have received your request for a free valuation and the information you provided, please note we will get back to you as soon as possible

Best Regards,
Diane
Silver Tree Estates
+27 11 675 1190
+27 82 802 0768
office@silvertreeestates.co.za
www.silvertreeestates.co.za";

if($fname == '') {print "You have not entered a name, please go back and try again";}
else {
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thanks.html" );}
else
{print "We encountered an error sending your mail, please notify office@silvertreeestates.co.za"; }
}
}
}
?>


Website Link:
http://www.silvertreeestates.co.za/#valuation

The error I seen to get it does not go to the thanks.html page, and I dont get the email

DyDr
11-17-2017, 01:54 PM
If you set php's error_reporting to E_ALL and display_errors to ON, php will help you by reporting and displaying all the errors it detects.

You have a hand full of mismatching names between your form fields and php variables, that would cause no values for some of the data. There would be undefined index and undefined variable error messages. Which, is the cause of your first reported symptom of always getting the name related validation error, before you edited your initial post in this thread.

The error_reporting/display_errors settings should also provide some help on finding why the header() redirect isn't working. You are likely sending output to the browser before the header() statement.

As to why the email is not being sent/received, these emails are NOT being sent from the email address that someone enters in the form and either the sending mail server is refusing to send them or the receiving mail server is refusing them. They are being sent from the mail server at your web hosting. The From: mail header needs to be an email address with a domain name that corresponds to your web hosting or there needs to be a SPF (Sender Policy Framework) dns record at the domain being used in the From: mail address that indicates the sending mail server at your web hosting is authorized to send email for that domain.

You should also apply htmlentities() to all the dynamic data being put into the email so that any html content, such as javascript, won't be rendered when the email is read. (I just submitted a problem report on major tv schedule web site, that contained a <div> tag in the text, the email reply I got contained my original report, but the <div> was rendered. Imagine what I could have done to the person who read my problem report if I had included javascrpt in it.)