milka milka - 11 months ago 63
PHP Question

After submiting a php form I get empty window and no e-mail


I've added echo $errors to the end of my code. Now I am getting that all fields are required although all are filled:

} else {
echo $errors;

I've created a simple php e-mail form with this example (link). And jQuery form validator (link).

Now what I get after submiting a form is just a empty "contact-form-handler.php" page.

You can see the form live at:

What could be the problem? Below is my code.


$errors = '';
$myemail = '';//<-----Put Your email address here.
if(empty($_POST['infoname']) ||
empty($_POST['infocompany']) ||
empty($_POST['infoemail']) ||
empty($_POST['infophone']) ||
$errors .= "\n Error: all fields are required";
$jobtype = $_POST['jobtype'];
$budget = $_POST['budget'];
$location = $_POST['location'];

$infoname = $_POST['infoname'];
$infocompany = $_POST['infocompany'];
$infoemail = $_POST['infoemail'];
$infophone = $_POST['infophone'];

if (isset($_POST['infodescription'])) {
$infodescription = $_POST['infodescription'];

if (!preg_match(
$errors .= "\n Error: Invalid email address";

if( empty($errors))
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Jobtype: $jobtype \n Budget: $budget \n Location: $location \n Name: $infoname \n Company: $infocompany \n E-mail: $infoemail \n Phone: $infophone \n ".
"Message \n $infodescription";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $infoemail";
//redirect to the 'thank you' page
// header('Location:');
header('Location: index.php');
} else {
echo $errors;

my form in index.php:

<form id="contactform" method="post" name="contact_form" action="contact-form-handler.php">
<div class="left">
<fieldset class="jobtype">
<legend>Job type</legend>
<input type="radio" name="jobtype" id="project" value="project" required>
<label for="project">Project</label>
<input type="radio" name="jobtype" id="part-time" value="part-time" >
<label for="part-time">Part-time</label>
<input type="radio" name="jobtype" id="full-time" value="full-time" >
<label for="full-time">Full-time</label>
<fieldset class="budget">
<input type="radio" name="budget" id="budget5k" value="budget5k" required>
<label for="budget5k">5k &euro; ></label>
<input type="radio" name="budget" id="budget10k" value="budget10k" >
<label for="budget10k">5k - 10k &euro;</label>
<input type="radio" name="budget" id="budget15k" value="budget15k" >
<label for="budget15k">15k &euro; <</label>
<fieldset class="location">
<input type="radio" name="location" id="locremote" value="locremote" required>
<label for="locremote">Remote</label>
<input type="radio" name="location" id="loclocal" value="loclocal" >
<label for="loclocal">Local with relocation</label>
<div class="right">
<fieldset class="contactinfo">
<legend>Your Contact Info</legend>
<div class="input-holder">
<input type="text" name="infoname" id="infoname" value="" required data-validation="alphanumeric">
<label for="infoname">Name</label>
<div class="input-holder">
<input type="text" name="infocompany" id="infocompany" value="" required data-validation="alphanumeric">
<label for="infocompany">Company</label>
<div class="input-holder">
<input type="text" name="infoemail" id="infoemail" value="" required data-validation="email">
<label for="infoemail">E-mail</label>
<div class="input-holder">
<input type="text" name="infophone" id="infophone" value="" required data-validation="number">
<label for="infophone">Phone</label>
<div class="input-holder textarea">
<textarea name="infodescription" form="contact_form" rows="4" required></textarea>
<label for="infodescription">Message</label>
<div class="input-holder submit">
<input type="submit" name="submit" value="Submit" required/>

Answer Source

text field should look like this don't put form tag in here

<textarea name="infodescription" rows="4" required></textarea>

in php make the if statement like this the first ( opens the if statement the last ) closes it and take not of how i used the other brackets

   (empty($_POST['infoname']))  ||
   (empty($_POST['infocompany'])) ||
   (empty($_POST['infoemail'])) ||
   (empty($_POST['infophone'])) ||
      $errors .= "\n Error: all fields are required";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download