简体   繁体   中英

Form works in Chrome and IE but not firefox

I created a form which works in Chrome and IE, but not Firefox. On submit, it simply goes to a blank screen with the URL of my PHP file, sendContact.php .

Here's the markup:

<form action="script/sendContact.php" method="post" class="contactForm">
  <div class="textBoxDivs">
    <label>Name</label>
    <br />
    <input type="text" id="name" name="name" size="40" class="textField"/>
  </div>
  <div class="textBoxDivs">
    <label>Phone</label>
    <br />
    <input type="text" id="phone" name="phone" size="40"class="textField"/>
  </div>
  <div class="textBoxDivs">
    <label>Email</label>
    <br />
    <input type="text" id="email" name="email" size="40"class="textField"/>
  </div>
  <div class="textArea">
    <label>Please describe what services you will require and your proposed budget.</label>
    <br />
    <textarea id="message" cols="40" rows="7" name="message" class="textAreaField">    </textarea>
  </div>
  <div class="formButtonDiv">
    <input type="submit" value="submit" class="formBut"/>
    <input type="reset" value="reset" class="formBut" />
  </div>
</form>

and the PHP is as follows:

$name       = $_POST['name'];
$email      = $_POST['email'];
$message    = $_POST['message'];
$phone      = $_POST['phone'];
$formcontent= "From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient  = "al@gmail.com";
$subject    = "Contact Form";
$mailheader = "From: $userEmail \r\n";

if (mail($recipient, $subject, $formcontent, $mailheader, $email))
{
  header ("Location: thankYou.html");
} else {
  echo "mail was not sent";
}

I've tried on Firefox right now, and every thing went fine. By the way, looking at your php code, you should check if the form is ok before sending it. I've tried with empty field and I guess you just receive a mail from nobody..

Try something like:

$name       = trim($_POST['name']);
$email      = trim($_POST['email']);
$message    = trim($_POST['message']);
$phone      = trim($_POST['phone']);

$formcontent= "From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient  = "alverdeja88@gmail.com";
$subject    = "Contact Form";
$mailheader = "From: $userEmail \r\n";

if (!empty($name) 
  && !empty($email)
  && !empty($message)
  && mail($recipient, $subject, $formcontent, $mailheader, $email))
{
  header ("Location: http://www.dukecitygrafx.com/thankYou.html");
}
else
{
  echo "mail was not sent";
}
  1. Remove the new Line in your html file (form Tag!). Firefox could have problems to solve this!

  2. Try a die("hello"); in your sendContact.php

So you can check whether your script will be loaded

<?php 
die("hello");

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST ['phone'];
$formcontent="From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient = "alverdeja88@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $userEmail \r\n";
if (mail($recipient, $subject, $formcontent, $mailheader, $email)) {
  header ("Location: http://www.dukecitygrafx.com/thankYou.html");
  die();
} else {
  echo "mail was not sent";
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM