This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I'm attempting to make an enquiry form on my site send an email regarding a booking. But I cannot work out my mistake in the PHP, very much a beginner to PHP so don't know where I went wrong.
I receive no email when testing the form on server.
<?php
$firstname = $_post['firstname'];
$lastname = $_post['lastname'];
$bandname = $_post['bandname'];
$email = $_post['email'];
$phoneno = $_post['phoneno'];
$startday = $_post['start_day'];
$startmonth = $_post['start_month'];
$starthour = $_post['start_hour'];
$startminute = $_post['start_minute'];
$endday = $_post['end_day'];
$endmonth = $_post['end_month'];
$endhour = $_post['end_hour'];
$endminute = $_post['end_minute'];
$extras = $_post['extras'];
$to = "some#emailaddress.com";
$subject = "New Message";
mail ($to, $subject, $firstname . $lastname, $bandname, $email, $phoneno, $start_day . $start_month, $start_hour . $start_minute, $end_day . $end_month, $end_hour . $end_minute, $extras);
?>
HTML of my form :
<form action="form.php" class="appnitro" id="form_1062945" method="post" name="form_1062945" style="display: inline-block;">
<div class="form_description medium-8 small-10 columns medium-centered small-centered" style="margin-bottom:45px">
<p>
Please complete the form below to send us details of the booking you would like to make, we will then get back to you within one business day to confirm your booking.
</p>
</div>
<ul>
<li class="small-6 columns" id="li_1">
<label class="description" for="element_1">First Name</label>
<div>
<input class="element text medium" id="element_1" maxlength="255" name="firstname" type="text" value="">
</div>
</li>
<li class="small-6 columns" id="li_2">
<label class="description" for="element_2">Last Name</label>
<div>
<input class="element text medium" id="element_2" maxlength="255" name="lastname" type="text" value="">
</div>
</li>
<li class="small-6 columns" id="li_3">
<label class="description" for="element_3">Company/band/artist</label>
<div>
<input class="element text medium" id="element_3" maxlength="255" name="bandname" type="text" value="">
</div>
</li>
<li class="small-6 columns" id="li_8">
<label class="description" for="element_8">Email</label>
<div>
<input class="element text medium" id="element_8" maxlength="255" name="email" type="text" value="">
</div>
</li>
<li class="small-6 end columns" id="li_4">
<label class="description" for="element_4">Phone number</label>
<div>
<input class="element text medium" id="element_4" maxlength="255" name="phoneno" type="text" value="">
</div>
</li>
<div class="row">
<div class="small-12 columns">
<li class="small-12 columns text-left" id="li_11">
<label class="description" for="element_11_1">Which space(s) are you interested in?</label>
<div class="line-boxes">
<span>
<input class="element checkbox" id="element_11_1" name="studio_1" type="checkbox" value="1">
<label class="choice" for="element_11_1">Studio 1</label>
</span>
</div>
<div class="line-boxes">
<span><input class="element checkbox" id="element_11_2" name="studio_2" type="checkbox" value="1">
<label class="choice" for="element_11_2" style="margin-bottom:20px">Studio 2</label>
</span>
</div>
</li>
</div>
</div>
<li class="small-12 medium-6 columns lose-pad" id="li_6">
<label class="description" for="element_6_1">Start Date</label>
<span class="small-6 columns">
<input class="element text" id="element_6_1" maxlength="2" name="start_day" size="2" type="text" value="">
<label for="element_6_1" style="font-size:10px">DD</label>
</span>
<span class="small-6 columns">
<input class="element text" id="element_6_2" maxlength="2" name="start_month" size="2" type="text" value="">
<label for="element_6_2" style="font-size:10px">MM</label>
</span>
</li>
<li class="medium-6 small-12 columns lose-pad" id="li_5">
<label class="description" for="element_5_1">Start Time</label>
<span class="small-6 columns">
<input class="element text" id="element_5_1" maxlength="2" name="start_hour" size="2" type="text" value="">
<label for="element_5_1" style="font-size:10px">HH</label>
</span>
<span class="small-6 columns">
<input class="element text" id="element_5_2" maxlength="2" name="start_minute" size="2" type="text" value="">
<label for="element_5_2" style="font-size:10px">MM</label>
</span>
</li>
<li class="small-12 medium-6 columns lose-pad" id="li_9">
<label class="description" for="element_9_2">End Date</label>
<span class="small-6 columns">
<input class="element text" id="element_9_2" maxlength="2" name="end_day" size="2" type="text" value="">
<label for="element_9_2" style="font-size:10px">DD</label>
</span>
<span class="small-6 columns">
<input class="element text" id="element_9_1" maxlength="2" name="end_month" size="2" type="text" value="">
<label for="element_9_1" style="font-size:10px">MM</label>
</span>
</li>
<li class="medium-6 small-12 columns lose-pad" id="li_7">
<label class="description" for="element_7_1">End Time</label> <span class="small-6 columns">
<input class="element text" id="element_7_1" maxlength="2" name="end_hour" size="2" type="text" value="">
<label for="element_7_1" style="font-size:10px">HH</label>
</span>
<span class="small-6 columns">
<input class="element text" id="element_7_2" maxlength="2" name="end_minute" size="2" type="text" value="">
<label for="element_7_2" style="font-size:10px">MM</label>
</span>
</li>
<li class="small-12 columns text-left" id="li_12">
<label class="description" for="element_12_1" style="margin-top:20px">Do you require or interested in any of the following additional services?</label>
<div class="line-boxes" style="margin-top:20px">
<span><input class="element checkbox" id="element_12_1" name="console_wedges" type="checkbox" value="1">
<label class="choice" for="element_12_1">House monitor console and wedges?</label>
</span>
</div>
<div class="line-boxes">
<span>
<input class="element checkbox" id="element_12_2" name="iem" type="checkbox" value="1">
<label class="choice" for="element_12_2">IEM System rental?</label>
</span>
</div>
<div class="line-boxes">
<span>
<input class="element checkbox" id="element_12_3" name="chairs" type="checkbox" value="1">
<label class="choice" for="element_12_3">Chairs?</label>
</span>
</div>
<div class="line-boxes">
<span>
<input class="element checkbox" id="element_12_4" name="stools" type="checkbox" value="1">
<label class="choice" for="element_12_4">Stools?</label>
</span>
</div>
<div class="line-boxes">
<span>
<input class="element checkbox" id="element_12_5" name="backline" type="checkbox" value="1">
<label class="choice" for="element_12_5">Backline rental?</label>
</span>
</div>
<div class="line-boxes">
<span>
<input class="element checkbox" id="element_12_6" name="transport" type="checkbox" value="1">
<label class="choice" for="element_12_6" style="margin-bottom:30px">Transport of equipment to or from Ritz</label> </span>
</div>
</li>
<li class="small-12 columns" id="li_10">
<label class="description" for="element_10">Anything else we should know to help assist with your booking?</label>
<div>
<textarea class="element textarea small" id="element_10" name="extras"></textarea>
</div>
</li>
<li class="buttons small-6 columns small-centered">
<input name="form_id" type="hidden" value="1062945">
<input class="button_text" id="saveForm" name="submit" type="submit" value="Submit">
</li>
</ul>
</form>
Firstly, all your $_post are incorrect.
That is a superglobal and must read as $_POST.
http://php.net/manual/en/language.variables.superglobals.php
Then you're injecting too many parameters in your mail() function.
Please read the manual:
http://php.net/manual/en/function.mail.php
Your server may not be setup to catch and display/log errors/notices/warnings.
Having used error reporting, would have thrown you many notices.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Related
I trying my cients select what services they want on email. I recevied the email but services are empty, mybe my php file is wrong. Thank you in advance
<h3>Tell us your inquiries</h3>
<hr>
<form id="contact-form" action="mailto:info#dosaladesign.com" method="post" onsubmit="return checkform(this);">
<div class="form-group">
<label for="firstname">First Name <span class="form-required" title="This field is required.">*</span></label>
<input type="text" name="firstname" class="form-control half" id="firstname" required>
</div>
<div class="form-group">
<label for="lastname">Last Name <span class="form-required" title="This field is required.">*</span></label>
<input type="text" name="lastname" class="form-control half" id="lastname" required>
</div>
<div class="form-group">
<label for="email">E-mail <span class="form-required" title="This field is required.">*</span></label>
<input type="email" name="email" class="form-control half" id="email" required>
</div>
<div class="form-group">
<label for="subject">Zip Code <span class="form-required" title="This field is required.">*</span></label>
<input type="text" name="zipcode" class="form-control half" id="zipcode" required>
</div>
<div class="form-group" >
<label for="email">Select Services</label>
<div class="row1">
<div class="col1"><input id="chk1" type="checkbox"><label>As-Built</label></div>
<div class="col1"><input id="chk2" type="checkbox" onclick="myFunction('New Construction Design','chk2')"/><label>New Construction Design</label></div>
<div class="col1"><input id="chk3" type="checkbox" onclick="myFunction('Residential Remodels','chk3')"/><label>Residential Remodels</label></div>
<div class="col1"><input id="chk4" type="checkbox" onclick="myFunction('Residential Additions','chk4')"/><label>Residential Additions</label></div>
<div class="col1"><input id="chk5" type="checkbox" onclick="myFunction('3D Modeling and Renderings','chk5')"/><label>3D Modeling and Renderings</label></div>
<div class="col1"><input id="chk6" type="checkbox" onclick="myFunction('Interior Design','chk6')"/><label>Interior Design</label></div>
<div class="col1"><input id="chk7" type="checkbox" onclick="myFunction('Space Planning and Furniture Layouts','chk7')"/><label>Space Planning and Furniture Layouts</label></div>
<div class="col1"><input id="chk8" type="checkbox" onclick="myFunction('Custom Furniture Design','chk8')"/><label>Custom Furniture Design</label></div>
<div class="col1"><input id="chk9" type="checkbox" onclick="myFunction('Landscape Design','chk9')"/><label>Landscape Design</label></div>
</div>
</div>
<div class="form-group">
<label for="message">Message <span class="form-required" title="This field is required.">*</span></label>
<textarea name="message" class="form-control" rows="4" id="message" required></textarea>
Ensure that your input elements contain a name attribute and value. According to the specs: If no name is specified, or name is empty, the input's value is not submitted with the form.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#name
Could someone tell me what to put in a separate php file to make this html form email the results to me. I have no idea what to do. I tried to copy a php file from online. It is horrible.
<form id="form_1138955" class="appnitro" method="post" action="/form/contact-form.php">
<div class="form_description">
<h2>Contact Us</h2>
<p></p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="name">Name* </label>
<span>
<input id="name_first" name= "name_first" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="name_last" name= "name_last" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li> <li id="li_3" >
<label class="description" for="email">Email*</label>
<div>
<input id="email" name="email" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label class="description" for="phone">Phone*</label>
<span>
<input id="phone_123" name="phone_123" class="element text" size="3" maxlength="3" value="" type="text"> -
<label for="phone_123">(###)</label>
</span>
<span>
<input id="phone_456" name="phone_456" class="element text" size="3" maxlength="3" value="" type="text"> -
<label for="phone_456">###</label>
</span>
<span>
<input id="phone_7890" name="phone_7890" class="element text" size="4" maxlength="4" value="" type="text">
<label for="phone_7890">####</label>
</span>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="1" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
You should put some settings like:
sender Email & password
protocol (smtp,mail,etc..)
Email port - READ HERE
I am trying to create a contact form, however, I cannot figure out how to create the PHP to send this filled out form to whichever email I specify and let the user know if success/fail. Can someone please help me with this?
Thank You
<form id="form_1109748" class="appnitro" method="post" action="">
<div class="form_description">
<h2>E-mail Form</h2>
<p>You can call us at (416) 247-8080 or fill out the form below to get in touch!</p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">Name </label>
<span>
<input id="element_1_1" name= "element_1_1" class="element text" maxlength="255" size="25" value=""/>
<label>First</label>
</span>
<span>
<input id="element_1_2" name= "element_1_2" class="element text" maxlength="255" size="25" value=""/>
<label>Last</label>
</span>
</li> <li id="li_2" >
<label class="description" for="element_2">Phone </label>
<span>
<input id="element_2_1" name="element_2_1" class="element text" size="5" maxlength="3" value="" type="text"> -
<label for="element_2_1">(###)</label>
</span>
<span>
<input id="element_2_2" name="element_2_2" class="element text" size="5" maxlength="3" value="" type="text"> -
<label for="element_2_2">###</label>
</span>
<span>
<input id="element_2_3" name="element_2_3" class="element text" size="8" maxlength="4" value="" type="text">
<label for="element_2_3">####</label>
</span>
</li> <li id="li_3" >
<label class="description" for="element_3">Email </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label class="description" for="element_4">Car Make </label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label class="description" for="element_5">Car Model </label>
<div>
<input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label class="description" for="element_6">Message </label>
<div>
<textarea id="element_6" name="element_6" class="element textarea medium"></textarea>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="1109748" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
This is an extremely basic version of what you are looking for. You should learn how to verify the contents of your form fields with PHP before the email is actually sent to avoid any security risks. But again, this will do what you want.
<?php
/* If the form has been submitted. If means that the code between the { and } will only be executed if the statement is true. */
if(isset($_POST['submit'])){
//change the part inside the quotes to change the mailto address
$mailto = "someaddress#somedomain.com";
$subject = "Your Subject";
//$_POST is the variable that gets all your form information. It's an array and the array elements(e.g.['element_1_1']) correspond with the names of your form elements.
$message = '
Name: '.$_POST['element_1_1'].'<br>
Phone: '.$_POST['element_2_1'].' '.$_POST['element_2_2'].'-'.$_POST['element_2_3'].'<br>
Email: '.$_POST['element_3'].'<br>
Car Make: '.$_POST['element_4'].'<br>
Car Model: '.$_POST['element_5'].'<br>
Message: '.$_POST['ement_6'];
//We are telling the email script that the message will be made up of HTML
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//If the mail message was sent, tell the user it was. If it wasn't, tell the user it was not sent.
if(mail($mailto, $subject, $_POST['element_6'], $headers)){
echo "Your email has been sent.";
} else {
echo "Could not send your email.";
}
//The form hasn't been submitted, so display the HTML of the form.
} else { ?>
<form id="form_1109748" class="appnitro" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="form_description">
<h2>E-mail Form</h2>
<p>You can call us at (416) 247-8080 or fill out the form below to get in touch!</p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">Name </label>
<span>
<input id="element_1_1" name= "element_1_1" class="element text" maxlength="255" size="25" value=""/>
<label>First</label>
</span>
<span>
<input id="element_1_2" name= "element_1_2" class="element text" maxlength="255" size="25" value=""/>
<label>Last</label>
</span>
</li> <li id="li_2" >
<label class="description" for="element_2">Phone </label>
<span>
<input id="element_2_1" name="element_2_1" class="element text" size="5" maxlength="3" value="" type="text"> -
<label for="element_2_1">(###)</label>
</span>
<span>
<input id="element_2_2" name="element_2_2" class="element text" size="5" maxlength="3" value="" type="text"> -
<label for="element_2_2">###</label>
</span>
<span>
<input id="element_2_3" name="element_2_3" class="element text" size="8" maxlength="4" value="" type="text">
<label for="element_2_3">####</label>
</span>
</li> <li id="li_3" >
<label class="description" for="element_3">Email </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label class="description" for="element_4">Car Make </label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label class="description" for="element_5">Car Model </label>
<div>
<input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label class="description" for="element_6">Message </label>
<div>
<textarea id="element_6" name="element_6" class="element textarea medium"></textarea>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="1109748" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
<?php
}
?>
I apologize in advance if this is an easy fix as I'm somewhat new to learning PHP. I found related questions and tried those answers, but none applied to my issue.
I am receiving an email from my contact form where some of the fields show up and some do not. On the Address field, I only receive the country, and for the Date Available field, I only receive the year. These are the current issues. I thought maybe it could be the input id, but it is only those two giving me a problem right now.
I sincerely appreciate any help you can offer.
PHP:
<?php
$myemail = "myemail#gmail.com";
$subject = "Employment Application Submission from Your Website";
/* Check all form inputs using check_input function */
$position = check_input($_POST['position']);
$refer = check_input($_POST['refer']);
$name = check_input($_POST['name'], "Enter your name");
$address = check_input($_POST['address']);
$phone = check_input($_POST['phone']);
$email = check_input($_POST['email']);
$dateavail = check_input($_POST['dateavail']);
$social = check_input($_POST['social']);
$dob = check_input($_POST['dob']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
Position Applied For: $position
Referred by: $refer
Name: $name
Address: $address
Phone: $phone
E-mail: $email
Date available: $dateavail
SSN: $social
DOB: $dob
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
HTML:
<form id="form_884913" method="post" action="send_form_email1.php" class="appnitro">
<ul >
<li id="li_1" >
<label class="description" for="position">Position Applied For </label>
<div>
<input id="element_1" name="position" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_2" >
<label class="description" for="refer">How were you referred to us? </label>
<div>
<input id="element_2" name="refer" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label class="description" for="name">Full Name (first, middle, last) </label>
<div>
<input id="element_3" name="name" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label class="description" for="address">Address </label>
<div>
<input id="element_4_1" name="address" class="element text large" value="" type="text">
<label for="address" style="font-size: 12px;">Street Address</label>
</div>
<div>
<input id="element_4_2" name="address" class="element text large" value="" type="text">
<label for="address" style="font-size: 12px;">Address Line 2</label>
</div>
<div class="left">
<input id="element_4_3" name="address" class="element text medium" value="" type="text">
<label for="address" style="font-size: 12px;">City</label>
</div>
<div class="right">
<input id="element_4_4" name="address" class="element text medium" value="" type="text">
<label for="address" style="font-size: 12px;">State / Province / Region</label>
</div>
<div class="left">
<input id="element_4_5" name="address" class="element text medium" maxlength="15" value="" type="text">
<label for="address" style="font-size: 12px;">Postal / Zip Code</label>
</div>
<div class="right">
<select class="element select medium" id="element_4_6" name="address">
<option value="" selected="selected"></option>
<option value="Afghanistan" >Afghanistan</option>
</select>
<label for="address" style="font-size: 12px;">Country</label>
</div>
</li> <li id="li_5" >
<label class="description" for="phone">Phone </label>
<span>
<input id="element_5_1" name="phone" class="element text" size="3" maxlength="3" value="" type="text"> -
<label for="element_5_1">(###)</label>
</span>
<span>
<input id="element_5_2" name="phone" class="element text" size="3" maxlength="3" value="" type="text"> -
<label for="element_5_2">###</label>
</span>
<span>
<input id="element_5_3" name="phone" class="element text" size="4" maxlength="4" value="" type="text">
<label for="element_5_3">####</label>
</span>
</li> <li id="li_6" >
<label class="description" for="email">E-Mail Address </label>
<div>
<input id="element_6" name="email" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_7" >
<label class="description" for="dateavail">Date Available to Start </label>
<span>
<input id="element_7_1" name="dateavail" class="element text" size="2" maxlength="2" value="" type="text"> /
<label for="dateavail">MM</label>
</span>
<span>
<input id="element_7_2" name="dateavail" class="element text" size="2" maxlength="2" value="" type="text"> /
<label for="dateavail">DD</label>
</span>
<span>
<input id="element_7_3" name="dateavail" class="element text" size="4" maxlength="4" value="" type="text">
<label for="dateavail">YYYY</label>
</span>
<span id="calendar_7">
<img id="cal_img_7" class="datepicker" src="calendar.gif" alt="Pick a date.">
</span>
<script type="text/javascript">
Calendar.setup({
inputField : "element_7_3",
baseField : "element_7",
displayArea : "calendar_7",
button : "cal_img_7",
ifFormat : "%B %e, %Y",
onSelect : selectDate
});
</script>
</li> <li id="li_8" >
<label class="description" for="social">Social Security Number </label>
<div>
<input id="element_8" name="social" class="element text small" type="text" maxlength="255" value=""/>
</div>
(I did not display the entire form for length purposes)
You have several input's with the same name. You need to give each input element a unique name. If you have multiple elements with the same name only the last one will be sent to the server.
An easy solution:
Change your PHP:
$address = check_input($_POST['address']." ".$_POST['address2']." ".$_POST['address3']." ".$_POST['address4']." ".$_POST['address5']);
Change your HTML:
<div>
<input id="element_4_1" name="address" class="element text large" value="" type="text">
<label for="address" style="font-size: 12px;">Street Address</label>
</div>
<div>
<input id="element_4_2" name="address2" class="element text large" value="" type="text">
<label for="address2" style="font-size: 12px;">Address Line 2</label>
</div>
<div class="left">
<input id="element_4_3" name="address3" class="element text medium" value="" type="text">
<label for="address3" style="font-size: 12px;">City</label>
</div>
<div class="right">
<input id="element_4_4" name="address4" class="element text medium" value="" type="text">
<label for="address4" style="font-size: 12px;">State / Province / Region</label>
</div>
<div class="left">
<input id="element_4_5" name="address5" class="element text medium" maxlength="15" value="" type="text">
<label for="address5" style="font-size: 12px;">Postal / Zip Code</label>
</div>
You have multiple <input> with the same name:
<input id="element_4_1" name="address" class="element text large" value="" type="text">
<input id="element_4_2" name="address" class="element text large" value="" type="text">
Since the name is what appears as the key in $_POST, you're essentially overwriting all of your inputs with the LAST name="address" that appears in the form.
Each input must have a unique name. Which you already have in your $foo = $_POST[...], so why you don't have the matching names in your form is a mystery.
you are using same names for input fields .. give different names for name attributes in input fields.
<input id="element_4_1" name="streetaddress" class="element text medium" value="" type="text">
<input id="element_4_2" name="addressline2" class="element text medium" value="" type="text">
while receiving in php.. get one by one. example
$doorNo = $_POST['streetaddress'];
$streetName= $_POST['addressline2'];
like wise for all fields.. same applies to all other issues.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
So i have used this website for a long time, and never had to ask before, but I am pulling my hair out! Help me please.
I am using a simple script i found using a form to send results to an email address. To start with the validation of 2 fields being full wont let it send, although the fields hold data - So i remove that condition and it will send an email, but it wont show the actual data displayed. Can you please look and suggest?
My PHP:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name - $_POST['name'];
$description - $_POST['description'];
$car_year - $_POST['car_year'];
$big_brakes - $_POST['big_brakes'];
$road_car - $_POST['road_car'];
$type - $_POST['type'];
$email - $_POST['email'];
//Validate first
if(empty($name)||empty($email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'marketing#part-box.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $name".
$to = "marketing#part-box.com";//<== update the email address
$headers = "From: $email_from \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;
}
}
?>
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RAYS Wheels Quote</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>RAYS Wheels Quote</a></h1>
<ul >
<center><img src="images/Rays---Coming-soon-page_03.jpg" width="251" height="72" alt=""></td></center>
</ul>
<form method="post" name="myemailform" action="form-to-email.php">
<div class="form_description">
<center><p>Free Quote for RAYS Wheels, Give us the information we have asked for and we will find the Wheels for your Car.</p></center>
</div>
<ul >
<li id="li_1" >
<label for="name">name</label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_2" >
<label for="description" >Car Make and Model</label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label for="car_year">Car Year</label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label for="big_brakes" >Big Brakes Fitted? Yes / No</label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label for="road_car">Road Car / Motor sport?</label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label for="type" >Type of RAYS Wheel</label>
<div>
<input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<label class="email" >Your Email Address</label>
<div>
<input id="element_5" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="793428" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("myemailform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<div id="footer"></a>
<center><center><img src="images/Rays---Form-Footer.jpg" width="624" height="264" alt="Makes"></td></div>
</div></center>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
PHP
Change this from this:
$name - $_POST['name'];
$description - $_POST['description'];
$car_year - $_POST['car_year'];
$big_brakes - $_POST['big_brakes'];
$road_car - $_POST['road_car'];
$type - $_POST['type'];
$email - $_POST['email'];
to this:
$name = $_POST['name'];
$description = $_POST['description'];
$car_year = $_POST['car_year'];
$big_brakes = $_POST['big_brakes'];
$road_car = $_POST['road_car'];
$type = $_POST['type'];
$email = $_POST['email'];
HTML
Change from this:
<label for="name">name</label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_2" >
<label for="description" >Car Make and Model</label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label for="car_year">Car Year</label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label for="big_brakes" >Big Brakes Fitted? Yes / No</label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label for="road_car">Road Car / Motor sport?</label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label for="type" >Type of RAYS Wheel</label>
<div>
<input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<label class="email" >Your Email Address</label>
<div>
<input id="element_5" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
To This:
<label for="name">name</label>
<div>
<input id="element_1" name="name" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_2" >
<label for="description" >Car Make and Model</label>
<div>
<input id="element_2" name="description" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label for="car_year">Car Year</label>
<div>
<input id="element_6" name="car_year" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label for="big_brakes" >Big Brakes Fitted? Yes / No</label>
<div>
<input id="element_3" name="big_brakes" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label for="road_car">Road Car / Motor sport?</label>
<div>
<input id="element_4" name="road_car" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label for="type" >Type of RAYS Wheel</label>
<div>
<input id="element_5" name="type" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<label class="email" >Your Email Address</label>
<div>
<input id="element_5" name="email" class="element text medium" type="text" maxlength="255" value=""/>
</div>
Explanation
In PHP, change the minus sign to equal sign when setting the value from the $_POST variable.
In HTML, the value of the input will be passed to PHP script will be based on the name attribute. So, in order to pass the value after the submission, the HTML code like below:
`<input id="someid" name="test" />`
will be passed to PHP as
$_POST['test']