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.
Related
I have a task where I have to create a search table which has a first name, second name, address, mobile, email, street, and other fields.
My FIRST TASK is to enter any one field (eg: first name or last name or street) and get all users matching that one query(like street=Martin street then, I should get all customers in Martin-street or vorname=Micheal, then I must get all names starting with Micheal).
My SECOND TASK is: in the same search table I have to enter one query(eg: vorname or mobile) and get the customer information.
This above two tasks must be done in a single table, I have created the front-end as attached down and in the back-end, PHP is in some mistake and I couldn't find a solution even after a week.
HTML CODE:
<form method="post" action="form.php">
<br><br>
<br><br>
<!--Beginn des Anrede-->
<div class="form1"><br><br>
<div class="names">
<div class="anrede">
<label for="Anrede">Anrede
<select id="select" name="anrede" >
<option value="">--Please choose an option--</option>
<option value="herr">Herr</option>
<option value="frau">Frau</option>
<option value="andere">Andere</option>
</select>
</label></div>
<br><br>
<div><br>
<label class="desc" id="title1" for="text1">Vorname</label>
<div>
<input id="text1" name="text1" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="vorname">
</div>
</div>
<div><br><br>
<label class="desc" id="title1" for="text2">Nachname</label>
<div>
<input id="text2" name="text2" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Ihr Nachname">
</div>
</div>
<div><br>
<label class="desc" id="title1" for="text3">E-mail-Addresse</label>
<div>
<input id="text3" name="text3" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Email">
</div>
</div>
<div><br>
<label class="desc" id="title1" for="text4">Telefonnummer</label>
<div>
<input id="text4" name="text4" type="number" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Telefonnummer">
</div>
</div>
<div><br><br>
<label class="desc" id="title3" for="text5">
Geburtstag
</label>
<div>
<input id="text5" name="text5" type="date" spellcheck="false" value="" maxlength="255" tabindex="3">
</div>
</div>
<div><br><br>
<label class="desc" id="title3" for="text6">
Plz
</label>
<div>
<input id="text6" name="text6" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Postleitzahl">
</div><br><br>
<label class="desc" id="title3" for="text7">
Ort
</label>
<div>
<input id="text7" name="text7" type="text" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Dein Platz">
</div><br><br>
</div>
<div>
<label class="desc" id="title1" for="text8">Straße</label>
<div>
<input id="text8" name="text8" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Straße">
</div>
</div>
<div><br><br>
<label class="desc" id="title3" for="text9">
Hausnummer
</label>
<input id="text9" name="text9" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Hausnummer">
<label class="desc" id="title3" for="text9">
Hausnummerzusatz
</label>
<input id="text10" name="text10" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Zusätzliche Adresse">
<div><br><br>
<div class="sub">
<input type="submit" name="submit" value="Suche">
<input type="reset" name="reset" value="Reset">
</div>
<br><br><br></div>
</div>
</div>
</form>
PHP CODE:
if(isset($_POST['submit']) ){
$keyword=$_POST['text1'];
$statement= $myconnection->prepare("SELECT * FROM OL_trans WHERE vorname =? ");
$statement->execute([$keyword]);
$key = $statement->fetchAll();
foreach($key as $value){
echo '<br/>'.$value['vorname'].
' - '.$value['nachname'].
' - '.$value['strasse'].
' - '.$value['plz'].
' - '.$value['ort'].
' - '.$value['email'].
' - '.$value['telefon'].
' - '.$value['mobil'].'<br/><br/>';
}
}
Kindly help me in repairing my PHP code and get me done the above two tasks. A big kudos to one who gonna help me here. Thanks a lot in advance
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
}
?>
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.
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']