Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact form not working

Featured Replies

Hi, I have a relatively simple contact form but some of the fields are not submitting any info entered. I'm puzzled because I've used this method several times successfully but for some reason the Name, Phone and Email fields are not working. Yet the enquiry field is!!!??

Here's the html and php I'm using:

 

 <?php
$EmailFrom = "I put the company name here";
$EmailTo = "this is the email address to send the form to";
$Subject = "Website Consultation Enquiry";
$Name = Trim(stripslashes($_POST['Name'])); 
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$Emailaddress = Trim(stripslashes($_POST['Emailaddress']));
$Enquiry = Trim(stripslashes($_POST['Enquiry'])); 

// prepare email body text
$Body = "";
$Body .= "EmailFrom: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Emailaddress: ";
$Body .= $Emailaddress;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $Enquiry;
$Body .= "\n";


// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=consultationsent.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=messagenotsenttwh.html\">";
  
  function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
}
?>

And the HTML form:

  <form method="post" id="theform" action="consultation.php"> 
<fieldset> 
<p> 
Your Name:<br />
      <input type="text" class="txt" id="Name"/> 
    </p> 
    
      <p> 
Telephone Number:<br />
      <input type="text" class="txt" id="Telephone"/> 
    </p> 
    
 
    
        <p> 
Email Address:<br />
       <input type="text" name="Emailaddress" id="Emailaddress" class="txt"/> 
    </p> 
<p>    Additional information:<br />
<textarea name="Enquiry" type="txt" id="Enquiry"/></textarea> </p><p id="error">Please complete all fields before submitting.</p>  
<div id="submitbtns">
 <p> 
 <input type="submit" value="Submit" style="height: 25px; width: 247px"/> </p>
<p> <input type="reset" value="Reset" style="height: 25px; width: 247px"/></p> </div>

</fieldset> 
  </form> 

There is a javascript validation on this form but I don't think it's that or should I post that too???

Thanks for any advice.

your HTML form is incorrect try this


<form method="post" id="theform" action="consultation.php">
<fieldset>
<p>
Your Name:
<br />
<input type="text" class="txt" id="Name" name="Name" />
</p>
<p>
Telephone Number:
<br />
<input type="text" class="txt" id="Telephone" name="Telephone" />
</p>
<p>
Email Address:
<br />
<input type="text" name="Emailaddress" id="Emailaddress" class="txt" />
</p>
<p>
Additional information:
<br />
<textarea name="Enquiry" type="txt" id="Enquiry" /></textarea>
</p>
<p id="error">Please complete all fields before submitting.</p>
<div id="submitbtns">
<p>
<input type="submit" value="Submit" style="height: 25px; width: 247px" />
</p>
<p>
<input type="reset" value="Reset" style="height: 25px; width: 247px" />
</p>
</div>
</fieldset>
</form>
But i cant see why the email would not work maybe add the JS

Edited by D4Y0

you was not giving the html input a name attribute so for example $_POST['Emailaddress'] was not being set unless you are using JS to post the form if so you will need to post that up, or even better a link to the contact form would be easier

Btw you need a lowercase T on the word trim in your PHP even tho it will work both ways its good to get into a habit of not using uppercase letters in built in php functions.

...except for a capital L in Location as in header( "Location: $thankyouurl" ); which doesn't seem to work with a lower case l !

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.