Form shows success message but no email is received - php

I have a Bootstrap 3 form that displays the success message: "Your message has been sent" but I don't receive any emails. Not even in my spam/junk folder. It validates properly but no email is sent. Here's the PHP code. Please help!
PHP
<?php
// check if fields passed are empty
if(empty($_POST['firstname']) ||
empty($_POST['lastname']) ||
empty($_POST['address']) ||
empty($_POST['address2']) ||
empty($_POST['city']) ||
empty($_POST['state_province']) ||
empty($_POST['country']) ||
empty($_POST['zip']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['checkbox']) ||
empty($_POST['comment']) ||
{
echo "No arguments Provided!";
return false;
}
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state_province = $_POST['state_province'];
$country = $_POST['country'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$checkbox = $_POST['checkbox'];
$message = $_POST['comment'];
// create email body and send it
$to = 'email#example.com'; // put your email
$email_subject = "Contact form submitted by: $firstname";
$email_body = "You have received a new message. \n\n".
"Here are the details:\n \nFirst Name: $firstname \n Last Name: $lastname\n Address: $address\n Address2: $address2\n City: $city\n State/Province: $state_province\n Country: $country\n zip: $zip\n Phone: $phone\n Email: $email_address\n Checkbox: $checkbox\n Message: \n $message";
$headers = "From: $email_address\n";
$headers = "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
HTML
<form class="form-horizontal" role="form" id="ContactUs" novalidate>
<!-- First Name -->
<div class="form-group">
<label class="control-label col-md-4" for="firstname"><abbr title="Required field">*</abbr>First Name</label>
<div class="col-md-8">
<input type="text" class="form-control" id="firstname" name="firstname" placeholder="First Name" required data-validation-required-message="Please enter your first name">
<div class="help-block"></div>
</div>
</div>
<!-- Last Name -->
<div class="form-group">
<label class="control-label col-md-4" for="lastname"><abbr title="Required field">*</abbr>Last Name</label>
<div class="col-md-8">
<input type="text" class="form-control" id="lastname" name="lastname" placeholder="Last Name" required data-validation-required-message="Please enter your last name">
<div class="help-block"></div>
</div>
</div>
<!-- Address -->
<div class="form-group">
<label class="control-label col-md-4" for="address"><abbr title="Required field">*</abbr>Address</label>
<div class="col-md-8">
<input type="text" class="form-control" id="address" name="address" placeholder="Address" required data-validation-required-message="Please enter your address">
<div class="help-block"></div>
</div>
</div>
<!-- Address 2 -->
<div class="form-group">
<label class="control-label col-md-4" for="address2">Address 2</label>
<div class="col-md-8">
<input type="text" class="form-control" id="address2" name="address2" placeholder="Address 2">
</div>
</div>
<!-- City -->
<div class="form-group">
<label class="control-label col-md-4" for="city"><abbr title="Required field">*</abbr>City</label>
<div class="col-md-8">
<input type="text" class="form-control" id="city" name="city" placeholder="City" required data-validation-required-message="Please enter your city">
<div class="help-block"></div>
</div>
</div>
<!-- State/Province -->
<div class="form-group">
<label class="control-label col-md-4" for="state_province"><abbr title="Required field">*</abbr>State/Province</label>
<div class="col-md-8">
<input type="text" class="form-control" id="state_province" name="state_province" placeholder="State/Province" required data-validation-required-message="Please enter your State or Province">
<div class="help-block"></div>
</div>
</div>
<!-- Country -->
<div class="form-group">
<label class="control-label col-md-4" for="country"><abbr title="Required field">*</abbr>Country</label>
<div class="col-md-8">
<input type="text" class="form-control" id="country" name="country" placeholder="Country" required data-validation-required-message="Please enter your Country of residence">
<div class="help-block"></div>
</div>
</div>
<!-- Zip/Postal Code -->
<div class="form-group">
<label class="control-label col-md-4" for="zip"><abbr title="Required field">*</abbr>Zip/Postal Code</label>
<div class="col-md-8">
<input type="text" class="form-control" id="zip" name="zip" placeholder="Zip/Postal Code" required data-validation-required-message="Please enter your Zip or Postal Code">
<div class="help-block"></div>
</div>
</div>
<!-- Phone -->
<div class="form-group">
<label class="control-label col-md-4" for="phone">Phone</label>
<div class="col-md-8">
<input type="tel" class="form-control" id="phone" name="phone" placeholder="Phone">
</div>
</div>
<!-- Email Address -->
<div class="form-group">
<label class="control-label col-md-4" for="email"><abbr title="Required field">*</abbr>Email address</label>
<div class="col-md-8">
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address" required data-validation-required-message="Please enter your email">
<div class="help-block"></div>
</div>
</div>
<!-- Mailing List -->
<div class="form-group">
<label class="control-label col-md-4" for="checkbox">Include in mailing list</label>
<div class="col-md-8">
<input type="checkbox" class="form-control" id="checkbox" name="checkbox" value="1">
</div>
</div>
<!-- Comment -->
<div class="form-group">
<label class="control-label col-md-4" for="comment">Comment</label>
<div class="col-md-8">
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
</div>
<!-- Buttons -->
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<div id="success"> </div> <!-- For success/fail messages -->
<button type="submit" class="btn btn-primary pull-right">Submit</button>
</div>
</div>
</form>
UPDATE 8:50PM 03/09
I uploaded this to a different host and now, when I submit the form I'm getting an error :"Message cannot be sent!"

you are sending the email to "email#example.com"
Probably try sending it to your email address, by changing the $to variable.
Also change the headers. From This
$headers = "From: $email_address\n";
$headers = "Reply-To: $email_address";
To:
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address";
note the .= on the second line, this means add the string onto headers vs replacing the content of the variable.
And maybe change this:
mail($to,$email_subject,$email_body,$headers);
return true;
to
return mail($to,$email_subject,$email_body,$headers); // will return true on success send, or false if it failed to send.

Related

Contact us form: Mail not received [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I'm trying to create a contact us form with PHP. The problem is that, I'm not receiving the email in my account. When the submit button is clicked it takes me to the mail.php page where a "thank you" message is shown.
The code is as shown below:
<div class="container">
<div class="col-xs-offset-2 col-xs-10 col-sm-8">
<h2>Contact Us</h2>
<form action="mail.php" method="POST" class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2 col-xs-6" for="email">First Name:</label>
<div class="col-sm-6 col-xs-6">
<input type="text" class="form-control" id="fname" placeholder="First Name*" name="fname" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Last Name:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="lname" placeholder="last Name" name="lname" >
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email ID:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="email" placeholder="Email Address*" name="email" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="message">Message:</label>
<div class="col-sm-6">
<textarea id="form_message" name="message" class="form-control" placeholder="Message*" rows="4" required="required" data-error="Please, leave us a message."></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
The code for mail.php:
<?php
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $fname $lname \n Message: $message";
$recipient = "rubeena.ajeed#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
Please try using SMTP ?
PHPmailler.class
Download : https://github.com/PHPMailer/PHPMailer

Not receiving input from all fields from PHP contact form

This has been bugging me all day and I've given up trying to figure it out for myself, but the answer's probably really obvious...
My contact form works fine, however I don't receive input for all fields. I only get name, phone, email and message. I've given the form fields a name attribute so I'm not sure what's happening.
Here is the HTML:
<form name="sentMessage" id="contactForm" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="name" class="form-control" placeholder="Your Name *" name="name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="phone" class="form-control" placeholder="Your Phone Number *" name="phone" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" name="email" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" name="suburb" placeholder="Your Suburb *" id="suburb" required data-validation-required-message="Please enter your address.">
<p class="help-block text-danger"></p>
</div>
<div class="select">
<div class="col-sm-6">
<div class="form-group">
<select class="selectpicker" name="state" id="state" data-width="100%" data-height="100%" title="Choose State *" data-style="btn-primary">
<option>QLD</option>
<option>NSW</option>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-sm-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Post Code *" name="postcode" id="postcode" required data-validation-required-message="Please enter your post code.">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product1" id="product1" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity1" id="quantity1">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product2" id="product2" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity2" id="quantity2">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product3" id="product3" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity3" id="quantity3">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="form-group">
<textarea class="form-control" placeholder="Additional comments" name="message" id="message"></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl" name="submit">submit</button>
</div>
</div>
</form>
And the PHP:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'myname#mydomain.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "P Services Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details: From: $name\n Phone: $phone\n E-Mail: $email_address\n Suburb: $suburb\n State: $state\n Post Code: $postcode\n Product: $product1\n Quantity: $quantity1\n Product: $product2\n Quantity: $quantity2\n Product: $product3\n Quantity: $quantity3\n Message:\n $message";
$headers = "From: noreply#yourdomain.com\n";
$headers .= "Reply-To: $email_address";
if(mail($to,$email_subject,$email_body,$headers)){
echo "Mail sent successfully.";
}
else{ echo "Error.";
}
?>
make sure that, you've removed disabled tag in html elemets.
THIS IS WRONG. PHP WON'T RECOGONIZE YOUR ELEMENT.
<input type="text" disabled>
INSTED OF USING disabled you can use readonly.
THIS IS THE CORRECT METHORD
<input type="text" readonly>
Your code returns all the information for me
All i did was change the form method so all the data is being passed its just needs to be handled correctly in your PHP
The only thing you need to change is specify the method of form submission (POST or GET).
Either use
<form name="sentMessage" id="contactForm" novalidate method="POST">
OR
Access the form variables using $_GET like $_GET['name'])

PHP Email Form Won't Send Email - Can't Figure This Out [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm building a site, and am having problems with the php form. I have looked through and cannot find anything that I see as wrong. However, I am also not very proficient with PHP and have never created a form like this before. Thank you very much if you can help.
Here is the code:
PHP:
<?php
$company = $_POST['company'];
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$numberofvehicles = $_POST['numofvehicles'];
$date= $_POST['date'];
$time = $_POST['time'];
$address = $_POST['address'];
$to = 'email#email.com';
$subject = "GPS Form Request: $company\n";
$body = "From: $name\n E-Mail: $email\n Company:\n $company Phone: $phone\n Date: $date\n Time: $time\n Address: $address\n Number of Vehicles: $numberofvehicles\n";
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if(isset($_POST['submit']){
mail ($to, $subject, $body, $headers); //mail sends it to the SMTP server side which sends the email
echo "<p>Your message has been sent!</p>";
}
else {
echo "<p>Something went wrong, go back and try again!</p>";
}
?>
HTML:
<form id="contact-form" method="post" action="/php/email.php" role="form">
<fieldset>
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="company_name">Your Company's Name</label>
<input id="company_name" type="text" name="company" class="form-control" placeholder="Please enter your company's name *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="your_name">Your Name</label>
<input id="your_name" type="text" name="name" class="form-control" placeholder="Please enter your first and last name *" required="required" data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_email">Preferred Email</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your preferred email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_phone">Preferred Phone</label>
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your preferred phone number">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="vehicles_number">Number of Vehicles</label>
<input id="vehicles_number" type="text" name="numofvehicles" class="form-control" placeholder="How many vehicles for installation?">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="install_address">Installation Address</label>
<input id="input_address" type="text" name="address" class="form-control" placeholder="What is the installation address?">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="install_date">Choose a Date for Installation</label>
<input id="calendar" name="date" type="text" class="form-control" placeholder="Please choose a date for installation" >
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="install_time">Choose a Time for Installation</label>
<input id="install_time" type="time" name="phone" class="form-control" placeholder="Please choose a time for installation">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
</fieldset>
<fieldset>
<div class="col-md-12">
<input type="submit" id="submit" name="submit" class="btn btn-success btn-send" value="Send message">
</div>
</div>
</div>
</div>
</fieldset>
</form>
</container>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script>
$('#calendar').datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
});
</script>
</body>
</div>
You are missing a closing parenthesis bracket in your php if statement.
if(isset($_POST['submit']))
At the very end of that statement ^

PHP Form only emails 1 value

When I submit my html form I am only getting the $name value in my email. Also when I click submit instead of redirecting to my thank you html page the content of the thank you page appears underneath the form. Any ideas why? Here is my code...
HTML:
<section class="container content">
<div class="row">
<div class="center title col-sm-12">
<h2>Short Application Form</h2>
</div>
</div>
<h2>Personal Information</h2>
<form method="post" action="appemail.php" name="contactform" id="contactform" class="row">
<fieldset>
<div class="form-field col-sm-6">
<label for="name">First Name</label>
<span><input type="text" name="name" id="name"/></span>
</div>
<div class="form-field col-sm-6">
<label for="lastname">Last Name</label>
<span><input type="text" name="lastname" id="lastname"/></span>
</div>
<div class="form-field col-sm-6">
<label for="email">Email</label>
<span><input type="text" name="email" id="email"/></span>
</div>
<!--<div class="form-field col-sm-6">
<label for="email">Referral Name</label>
<span><input type="email" name="email" id="email"/></span>
</div>-->
<div class="form-field col-sm-6">
<label for="email">Home/Cell Phone</label>
<span><input type="text" name="phone" id="phone"/></span>
</div>
<div class="form-field col-sm-6">
<label>Martial Satus</label>
<select name="martial">
<option>Married</option>
<option>Unmaried</option>
<option>Seperated</option>
</select>
</div>
<div class="form-field col-sm-6">
<label>Are you a Canadian Permanent Resident</label>
<select name="resident">
<option>Yes</option>
<option>No</option>
</select>
</div>
<div class="form-field col-sm-6">
<label for="email">Date of Birth</label>
<span><input type="text" name="birth"/></span>
</div>
<div class="form-field col-sm-6">
<label for="email">Number of Dependents</label>
<span><input type="text" name="dependents"/></span>
</div>
<div class="center title col-sm-12">
<h2 style="text-align:left">Current Address</h2>
</div>
<div class="form-field col-sm-6">
<label for="name">Street Address</label>
<span><input type="text" name="adress"/></span>
</div>
<div class="form-field col-sm-6">
<label for="name">City</label>
<span><input type="text" name="city"/></span>
</div>
<div class="form-field col-sm-6">
<label for="name">Province</label>
<span><input type="text" name="province"/></span>
</div>
<div class="form-field col-sm-6">
<label for="name">Postal Code</label>
<span><input type="text" name="postal"/></span>
</div>
<div class="form-field col-sm-6">
<label for="name">Years at this Address</label>
<span><input type="text" name="years"/></span>
</div>
<div class="form-field col-sm-6">
<label>Rent or Own</label>
<select name="rent">
<option>Own</option>
<option>Rent</option>
</select>
</div>
<div class="center title col-sm-12">
<h2 style="text-align:left">Subject Property</h2>
</div>
<div class="form-field col-sm-6">
<label>Property Usage</label>
<select name="property">
<option>Primary Residence</option>
<option>Second Home</option>
<option>Investment</option>
</select>
</div>
<div class="form-field col-sm-6">
<label for="name">Loan Amount $ </label>
<span><input type="text" name="loan"/></span>
</div>
<div class="form-field col-sm-6">
<label for="name">Purchase Price $</label>
<span><input type="text" name="price"/></span>
</div>
<div class="center title col-sm-12">
<h2 style="text-align:left">Monthly Income</h2>
</div>
<div class="form-field col-sm-6">
<label for="name">Yearly Income $ </label>
<span><input type="text" name="yearly"/></span>
</div>
<div class="form-field col-sm-6">
<label for="name">Other Sources of Income (combined) $</label>
<span><input type="text" name="other"/></span>
</div>
<div class="form-field col-sm-12">
<label for="message">Comments</label>
<span><textarea name="message" id="message"></textarea></span>
</div>
</fieldset>
<div class="form-click center col-sm-12">
<span><input type="submit" name="submit" id="submit" value="Send it"/></span>
</div>
<div id="alert" class="col-sm-12"></div>
</form>
</section>
PHP:
<?php
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$martial = $_POST['martial'];
$resident = $_POST['resident'];
$birth = $_POST['birth'];
$dependents = $_POST['dependents'];
$adress = $_POST['adress'];
$city = $_POST['city'];
$province = $_POST['province'];
$postal = $_POST['postal'];
$years = $_POST['years'];
$rent = $_POST['rent'];
$property = $_POST['property'];
$loan = $_POST['loan'];
$price = $_POST['price'];
$other = $_POST['other'];
$message = $_POST['message'];
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = $visitor_email;
$email_subject = "Application Loan";
$email_body = "You have received a new message from $name\n\n".
"Here is the Application: \n\n".
"Phone: $phone\n\n".
"Martial Status: $martial\n\n".
"Resident: $resident\n\n".
"Birth: $birth\n\n".
"Dependents: $dependents\n\n".
"Address: $address\n\n".
"City: $city\n\n".
"Province: $province\n\n".
"Postal: $postal\n\n".
"Years at this Address: $years\n\n".
"Rent or Own: $rent\n\n".
"Property: $property\n\n".
"Loan: $loan\n\n".
"Price: $price\n\n".
"Other: $other\n\n".
"Message: $message\n\n";
$to = "email#gmail.com";//<== update the email address
$headers = "From: $visitor_email \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location:thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)','(\r+)','(\t+)','(%0A+)','(%0D+)','(%08+)','(%09+)' );
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)){return true;}
else{return false;}
}
?>
Thanks in advance.
The string concatenation doesn't work because of the newline.
rewrite your code and use <br> except \n & when submit form check data using isset function, add a hidden field for doing it.
I've copied over your code and it runs fine, except you have a typo with $address.
Sometimes you use address (which is the correct), and sometimes adress.
The email I received:
You have received a new message from First Name
Here is the Application:
Phone: 0000000
Martial Status: Married
Resident: Yes
Birth: 2014-10-19
Dependents: 42
Address: Street Address
City: City
Province: Province
Postal: Postal Code
Years at this Address: 42
Rent or Own: Own
Property: Primary Residence
Loan: 42
Price: 42
Other: 42
Message: Comments
The new display of lines will work with most email clients because there are no html tags, so it will be displayed as plain text. Setting the appropriate header also helps.
Otherwise, what is your back-end?
OS, host, PHP versions?

HTML not passing content to PHP contact form

<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Contact Me</h2>
<hr class="star-primary">
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<!-- To configure the contact form email address, go to mail/contact_me.php and update the email address in the PHP file on line 19. -->
<!-- The form should work on most web servers, but if the form is not working you may need to configure your web server differently. -->
<form name="sentMessage" id="contactForm" onsubmit="return validate()" action="contactme.php">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Email Address</label>
<input type="email" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Phone Number</label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<input type="submit" value="Submit" name="Submit" class="btn btn-success btn-lg"></input>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<-----PHP----->
<?php
if(empty($_POST['name']) ||
empty($_POST['emailz']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['emailz'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!!";
return false;
}
$name = $_POST['name'];
$email = $_POST['emailz'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from
$headers .= "Reply-To: $emailz";
$subject = 'New Message - Kieronb- $name';
$body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $emailz\n\nPhone: $phone\n\nMessage:\n$message";
mail("k#gmail.com",$subject,$body,$headers);
return true;
?>
SO, the above is the HTML and the PHP, now the majority of this code has been frankensteined from a bootstrap project, but i thought i would just have a play with the contact form too, but it is going all the way through to the missing arguments catch at the beginning of the PHP.
I cant see why the data is coming through empty- have i missed something painfully obvious?
I am running on a web server, not locally.
Thanks
Edit; thanks everyone, i forgot my method, and names on the form!
Your form fields do not have the name attribute. Without them their values are not submitted with the form.
<input type="email" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
should be
<input type="email" name="emailz" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
And your <form> needs to have the method specified as POST or else it defaults to GET:
<form method="post" name="sentMessage" id="contactForm" onsubmit="return validate()" action="contactme.php">

Categories