Results 1 to 2 of 2

Thread: Email Form

  1. #1
    Join Date
    Sep 2004
    Little Falls, Roodepoort, South Africa
    Thanked 1 Time in 1 Post

    Exclamation Email Form


    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"> 
        <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>

    PHP Code
    $to = "" ; 
    $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:"; 
    $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,
    Silver Tree Estates
    +27 11 675 1190
    +27 82 802 0768";
    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); 
    {header( "Location: thanks.html" );} 
    {print "We encountered an error sending your mail, please notify"; } 
    Website Link:

    The error I seen to get it does not go to the thanks.html page, and I dont get the email
    Last edited by simonf; 11-16-2017 at 02:00 PM.
    Very Best Rgds, Simonf :cool:
    My Site | E-Mail Me

  2. #2
    Join Date
    Jan 2015
    Thanked 19 Times in 19 Posts


    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.)
    Last edited by DyDr; 11-17-2017 at 02:05 PM.

Similar Threads

  1. html form to php email form
    By weiner769 in forum PHP
    Replies: 15
    Last Post: 02-05-2010, 06:26 PM
  2. Resolved PHP Form-to-Email won't post input into email
    By rsrwebs in forum PHP
    Replies: 6
    Last Post: 06-12-2009, 12:14 AM
  3. Replies: 2
    Last Post: 05-28-2008, 04:16 AM
  4. PHP Email Form not sending to email?
    By euphoriastudio in forum PHP
    Replies: 1
    Last Post: 02-14-2008, 08:04 PM
  5. Email Form
    By Dillbertdabomb in forum The lounge
    Replies: 5
    Last Post: 07-11-2006, 07:51 PM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts