Mail sends me a blank message and - php

Hi everyone,
With this form you send and an empty mail if you click on the submit button which should actually happen. Before that whenever I fill in the description textarea than I you can't see the description but the rest of the details are ok.
So my question is what exactly happened?
This is the Modal:
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="MAXDATA Support">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h3 class="modal-title" id="maxdata-title">Reparaturauftrag / VAT</h3>
</div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<p class="text-danger">* Pflichtfelder</p>
</div>
<div class="col-sm-6">
<div class="checkbox">
<label>
<input type="checkbox" name="vorabaustausch" <?php if (isset($vorabaustausch) && $vorabaustausch=="Vorabaustausch") echo "checked";?> value="Vorabaustausch"> Vorabaustausch
</label>
</div>
<div class="form-group">
<label for="defektesGereat">Defektes Gerät *</label>
<input type="text" name="defektesGereat" class="form-control" id="defektesGereat" value="<?php echo $defektesGereat;?>">
<p class="text-danger"><?php echo $def_err;?></p>
</div>
<div class="form-group">
<label for="artikelnummer">Artikelnummer *</label>
<input type="text" name="artikelnr" class="form-control" id="artikelnummer" value="<?php echo $artikelnr;?>">
<p class="text-danger"><?php echo $artikelnr_err;?></p>
</div>
<div class="form-group">
<label for="firma">Firma *</label>
<input type="text" name="firma" class="form-control" id="firma" value="<?php echo $firma;?>">
<p class="text-danger"><?php echo $firma_err; ?></p>
</div>
<div class="form-group">
<label for="strasse">Strasse *</label>
<input type="text" name="strasse" class="form-control" id="strasse" value="<?php echo $strasse;?>">
<p class="text-danger"><?php echo $strasse_err;?></p>
</div>
<div class="form-group">
<label for="email">Email *</label>
<input type="email" name="email" class="form-control" id="email" value="<?php echo $email;?>">
<p class="text-danger"><?php echo $email_err;?></p>
</div>
</div>
<div class="col-sm-6">
<div class="checkbox">
<label>
<input type="checkbox" name="waranty" <?php if (isset($waranty) && $waranty=="Garantiereparatur") echo "checked";?> value="Garantiereparatur"> Garantiereparatur
</label>
</div>
<div class="form-group">
<label for="serial">Seriennummer *</label>
<input type="text" name="serial" class="form-control" id="serial" value="<?php echo $serial;?>">
<p class="text-danger"><?php echo $serial_err;?></p>
</div>
<div class="form-group">
<label for="kundennummer">KdNr / Verkäufer *</label>
<input type="text" name="kdnr" class="form-control" id="kundennummer" value="<?php echo $kdnr;?>">
<p class="text-danger"><?php echo $kdnr_err;?></p>
</div>
<div class="row">
<div class="form-group col-sm-6">
<label for="name">Name *</label>
<input type="text" name="name" class="form-control" id="name" value="<?php echo $name;?>">
<p class="text-danger"><?php echo $name_err;?></p>
</div>
<div class="form-group col-sm-6">
<label for="vorname">Vorname *</label>
<input type="text" name="vorname" class="form-control" id="vorname" value="<?php echo $vorname;?>">
<p class="text-danger"><?php echo $vorname_err;?></p>
</div>
</div>
<div class="row">
<div class="form-group col-sm-5">
<label for="zip">PLZ *</label>
<input type="number" name="zip" class="form-control" id="zip" value="<?php echo $zip;?>">
<p class="text-danger"><?php echo $zip_err;?></p>
</div>
<div class="form-group col-sm-7">
<label for="ort">Ort *</label>
<input type="text" name="ort" class="form-control" id="ort" value="<?php echo $ort;?>">
<p class="text-danger"><?php echo $ort_err;?></p>
</div>
</div>
<div class="form-group">
<label for="phone">Telefon <small>(tagsüber)</small> *</label>
<input type="tel" name="phone" class="form-control" id="phone" value="<?php echo $phone;?>">
<p class="text-danger"><?php echo $phone_err;?></p>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label for="descr">Fehlerbeschreibung *</label>
<textarea class="form-control" name="descr" rows="5" style="resize:none;"><?php echo $descr;?></textarea>
<p class="text-danger"><?php echo $descr_err;?></p>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="confirmation"> Bitte schicken Sie mir eine Bestätigungsmail.
</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" name="submit" class="btn btn-maxdata">Senden</button>
</div>
</form>
</div>
</div>
This is PHP code:
<?php
$vorabaustausch = $waranty = $defektesGereat = $serial = $artikelnr = $kdnr = $firma = $name = $vorname = $strasse = $zip = $ort = $email = $phone = $descr = "";
$artikelnr_err = $serial_err = $def_err = $name_err = $email_err = $strasse_err = $zip_err = $ort_err = $phone_err = $descr_err = $vorname_err = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$vorabaustausch = test_input($_POST["vorabaustausch"]);
$waranty = test_input($_POST["waranty"]);
if (empty($_POST['defektesGereat'])) {
$def_err = 'Wie heisst Ihr defektes Gerät?';
} else {
$defektesGereat = test_input($_POST["defektesGereat"]);
}
if (empty($_POST["serial"])) {
$serial_err = "Serialnummer angeben!";
} else {
$serial = test_input($_POST["serial"]);
}
if (empty($_POST["artikelnr"])) {
$artikelnr_err = "Artikelnummer angeben!";
} else {
$artikelnr = test_input($_POST["artikelnr"]);
}
if (empty($_POST["kdnr"])) {
$kdnr_err = "Kundennummer angeben!";
} else {
$kdnr = test_input($_POST["kdnr"]);
}
if (empty($_POST["firma"])) {
$firma_err = "Firma angeben!";
} else {
$firma = test_input($_POST["firma"]);
}
// check if name only contains letters and whitespace
if (empty($_POST['name'])) {
$name_err = "Bitte Ihren Namen angeben!";
} else {
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$name_err = "Bitte NUR Buchstaben eingeben!";
}
}
if (empty($_POST['vorname'])) {
$name_err = "Bitte Ihren Vornamen angeben!";
} else {
$vorname = test_input($_POST["vorname"]);
if (!preg_match("/^[a-zA-Z ]*$/",$vorname)) {
$vorname_err = "Bitte NUR Buchstaben eingeben!";
}
}
if (empty($_POST["strasse"])) {
$strasse_err = "Strasse angeben!";
} else {
$strasse = test_input($_POST["strasse"]);
}
if (empty($_POST["zip"])) {
$zip_err = "Postleitzahl angeben!";
} else {
$zip = test_input($_POST["zip"]);
}
if (empty($_POST["ort"])) {
$ort_err = "Ort angeben!";
} else {
$ort = test_input($_POST["ort"]);
if (!preg_match("/^[a-zA-Z ]*$/",$ort)) {
$ort_err = "Ortschaft angeben!";
}
}
if (empty($_POST["email"])) {
$email_err = "Email angeben!";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Ungültige Email Format";
}
}
if (empty($_POST["phone"])) {
$phone_err = "Telefon angeben!";
} else {
$phone = test_input($_POST["phone"]);
}
if (empty($_POST["descr"])) {
$descr_err = "Beschreiben Sie bitte Ihr Anliegen!";
} else {
$descr = test_input($_POST["descr"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST['submit'])) {
$to = "web#banovi-partner.ch";
$from = $_POST['email'];
if(isset($_POST['vorabaustausch'])) {
$subject = $_POST['vorabaustausch'] . " " . $vorname. " " . $name;
} elseif(isset($_POST['waranty'])) {
$subject = $_POST['waranty'] . " " . $vorname . " " . $name;
}
$subject2 = "Bestätigung Auftrag" . "\r\n";
$headers = "From: " . $email . "\r\n";
$headers .= "MIME-Version: 1.0 \r\n";
$headers .= 'Content-type: text/html; charset=UTF-8';
$message = '<html>
<style>
body {
font-family: "Roboto", sans-serif;
}
</style>
<body>';
$message .= '<h1>' . $vorabaustausch . $waranty . ' von ' . $defektesGereat .'</h1>';
$message .= '<hr><br>';
$message .= '<h4><strong>Von: </strong> ' . $name . ' ' . $vorname . '</h4>';
$message .= '<strong>Defektes Gerät: </strong>' . $defektesGereat . '<br>';
$message .= '<strong>Artikelnummer:</strong> ' . $artikelnr . '<br>';
$message .= '<strong>Seriennummer:</strong> ' . $serial . '<br>';
$message .= '<strong>Kundenummer / Verkäufer:</strong> ' . $kdnr . '<br>';
$message .= '<strong>Firma:</strong> ' . $firma . '<br><br>';
$message .= '<strong>Adresse:</strong> <br>';
$message .= $name . ' ' . $vorname . '<br>' . $strasse . '<br>' . $zip . ' ' . $ort . '<br><br>';
$message .= '<strong>Email:</strong> ' . $email . '<br><br>';
$message .= '<strong>Telefon:</strong> ' . $phone . '<br><br>';
$message .= '<strong>Fehlerbeschreibung:</strong><br>';
$message .= $descr . '<hr>';
$message .= '</body></html>';
$confirmation_mail = "Ihre Auftrags Kopie: " . "<br><br>" . $vorabaustausch . $waranty . $defektesGereat . $serial . $artikelnr . $kdnr . $firma . $name . $vorname . $strasse . $zip . $ort . $phone . $message;
mail($to,$subject,$message,$headers);
if(isset($_POST['confirmation'])) {
}
}
?>
Please help me :)
Thank you in regards,

Check your opening form tag. Try to put 'PHP_SELF' instead "PHP_SELF".

Related

sending mail after adding attachment code in ajax form submission not working

im trying to send email with attachment using ajax, if dont use attachment code email is send successfully, but when i add attachment code then nothing happens no error nothing at all.
`<form enctype="multipart/form-data" id="first_form" method="POST" class="get-contact-form" action="get-quote.php">
<div class="row g-3">
<div class="col-sm-6">
<div class="form-floating">
<input type="hidden" class="form-control" id="spam" name="spam" placeholder="Spam:" value="<?php echo $silk; ?>">
<p class='response' id="spam_error"></p>
</div>
</div>
<div class="col-sm-6">
<div class="form-floating">
<input type="hidden" class="form-control" id="blank" name="blank" placeholder="blank:" value="">
<p class='response' id="blank_error"></p>
</div>
</div>
<div class="col-sm-6">
<div class="form-floating">
<input type="text" name="name" class="form-control" id="gname" placeholder="Gurdian Name">
<label for="gname">Your Name</label>
<p class='response' id="name_error"></p>
</div>
</div>
<div class="col-sm-6">
<div class="form-floating">
<input type="email" name="email" class="form-control" id="gmail" placeholder="Gurdian Email">
<label for="gmail">Your Email</label>
<p class='response' id="email_error"></p>
</div>
</div>
<div class="col-sm-6">
<div class="form-floating">
<input type="text" name="phone" class="form-control" id="cname" placeholder="Child Name">
<label for="cname">Your Phone</label>
<p class='response' id="phone_error"></p>
</div>
</div>
<div class="col-sm-6">
<div class="form-floating">
<input type="text" name="address" class="form-control" placeholder="Child Age">
<label for="cage">Address</label>
<p class='response' id="address_error"></p>
</div>
</div>
<div class="col-sm-6">
<div class="form-floating">
<input type="text" name="subject" class="form-control" id="cage" placeholder="Child Age">
<label for="cage">Subject</label>
<p class='response' id="subject_error"></p>
</div>
</div>
<div class="col-sm-6">
<div class="form-floating">
<input type="text" name="services" class="form-control" id="cage" placeholder="Child Age">
<label for="cage">Service Type</label>
<p class='response' id="services_error"></p>
</div>
</div>
<div class="col-sm-12">
<div class="form-floating">
<input type="file" name="my_file" class="form-control" id="my_case_file" placeholder="Child Age">
<p class='response' id="my_file_error"></p>
</div>
</div>
<div class="col-12">
<div class="form-floating">
<textarea class="form-control" name="message" placeholder="Leave a message here" id="message" style="height: 80px"></textarea>
<label for="message">Message</label>
<p class='response' id="message_error"></p>
</div>
</div>
<div class="col-12">
<button class="btn secondary-bg text-white py-3 px-5" name="submit" type="submit">Get A Free Quote</button>
</div>
</div>
</form>`
php code for sending mail, when i add attachement code for sending image through mail following code doesnt send mail... but if remove attachment code form following code the form works percetly with ajax submission
session_start();
$floor = $_SESSION['token'];
$errorsbag = [];
$count_errors = 0;
$post = [];
$errors = [];
// List of the words you want to block
$spam_words =
["http", "www", ".com","#",".mx", ".org",
".net", ".co.uk",
".jp", ".ch", ".info", ".me",
".mobi", ".us", ".biz", ".ca",
".ws", ".ag",".com.co", ".net.co",
".com.ag", ".net.ag", ".it", ".fr",
".tv", ".am", ".asia", ".at", ".be",
".cc", ".de","dollars",
"payment", "website", "games", "toys", "poker",
"cheap", "href","nude","cam","penis","pills",
"sale","cheapest", "script",'Mod', 'Owner',
'Mawd', 'M0d', '0wner','090','080','081','070','
091','0-','+','80','81','70','91','dot','f*ck',
'bitch','ww','cum','hacker','money','Buy','Order',
'Meet singles','Near you','Near you','Additional income',
'Be your own boss','Robot, '<','>'
];
function is_blank($value) {
return !isset($value) || trim($value) === '';
}
// post method form processing
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$post = array_map('trim',$_POST);
// validate inputs
if($post['name'] === '')
{
$errors['name'] = "Name is required.";
}
if($post['email'] === '')
{
$errors['email'] = "Email is required.";
}
else if(!filter_var($post['email'], FILTER_VALIDATE_EMAIL))
{
$errors['email'] = "Email format is not valid.";
}
if($post['phone'] === '')
{
$errors['phone'] = "Phone is required.";
}
if($post['address'] === '')
{
$errors['address'] = "Address is required.";
}
if($post['subject'] === '')
{
$errors['subject'] = "Subject is required.";
}
if($post['services'] === '')
{
$errors['services'] = "Services is required.";
}
if($post['message'] === '')
{
$errors['message'] = "Message is required.";
}
$comment = $post['message']; // This should be coming from a post request
$comment_str = (string)$comment;
$new_input = str_replace(' ', '', strtolower($comment_str));
if(!is_blank($comment)){
foreach($spam_words as $item) {
if (strpos($new_input, strtolower($item)) !== false) {
$errorsbag[] = $item;
}
}
}
$count_errors = count($errorsbag);
if ($count_errors >= 1) {
$errors['message'] = "";
}
if($post['spam'] !== $floor){
$errors['spam'] = "";
}elseif($post['blank'] !== ''){
$errors['blank'] = "";
}elseif($count_errors >= 1){
$errors['message'] = "";
}
// if no errors, use the form data
if(empty($errors)){
$name = contact_input($post['name']);
$email = contact_input($post['email']);
$phone = contact_input($post['phone']);
$address = contact_input($post['address']);
$subject = contact_input($post['subject']);
$services = contact_input($post['services']);
$message = contact_input($post['message']);
$info =
'<table border="1" cellspacing="0" width="60%" cellpadding="10px">
<tr style="height: 21px;">
<td colspan="2" bgcolor="#dddfe2 " align="center" style="font-family: Verdana, Geneva, sans-serif; font-size: 14px; color: #000; height: 21px;"><b>Mail From Client: '.$name.'</b></td>
</tr>
<tr>
<td>Name:</td>
<td>'.$name.'</td>
</tr>
<tr>
<td>Email:</td>
<td>'.$email.'</td>
</tr>
<tr>
<td>Phone:</td>
<td>'.$phone.'</td>
</tr>
<tr>
<td>Services:</td>
<td>'.$services.'</td>
</tr>
<tr>
<td>Message:</td>
<td>'.$message.'</td>
</tr>
</table>';
//Get uploaded file data
$file_tmp_name = $_FILES['my_file']['tmp_name'];
$file_name = $_FILES['my_file']['name'];
$file_size = $_FILES['my_file']['size'];
$file_type = $_FILES['my_file']['type'];
$file_error = $_FILES['my_file']['error'];
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("random");
//header
$headers = "MIME-Version: 1.0\r\n"; // Defining the MIME version
$headers .= "From:".$email."\r\n"; // Sender Email
$headers .= "Content-Type: multipart/mixed;"; // Defining Content-Type
$headers .= "boundary = $boundary\r\n"; //Defining the Boundary
//plain text
$body = "--$boundary\r\n";
$body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($info));
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=".$file_name."\r\n";
$body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
$subject = "Mail From Client";
$mailTo = "satish.innovstudio#gmail.com";
mail($mailTo, $subject, $body,$headers);
}
$response = [];
if(empty($errors) || $post['spam'] !== $floor || $post['blank'] !== '' || $count_errors >= 1){
$response['success_message'] = "Thank you for your message!<br>We'll get back to you as soon as We can.";
}
else{
foreach($errors as $key=>$value)
{
$response[$key.'_error'] = $value;
}
}
echo json_encode($response);
}
function contact_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}`

Form does not check reCaptcha

I have a form that I want to add ReCaptcha to, however, somewhere along the line something isnt working correctly because my form will still submit whether or not reCaptcha is verified.
This is the form:
<?php if(isset($_GET[ 'CaptchaPass'])){ ?>
<div>Thank you! Your Form was Successfully Submitted</div>
<?php } ?>
<?php if(isset($_GET[ 'CaptchaFail'])){ ?>
<div>Captcha Error. Please verify that you are human!</div>
<?php } ?>
<form action="http://vmobileautoglass.com/php/func_contact.php">
<label>Name</label> <span class="color-red">*</span>
<div class="row margin-bottom-20">
<div class="col-md-6 col-md-offset-0">
<input class="form-control" type="text" name="name">
</div>
</div>
<label>Email
<span class="color-red">*</span>
</label>
<div class="row margin-bottom-20">
<div class="col-md-6 col-md-offset-0">
<input class="form-control" type="text" name="email">
</div>
</div>
<label>Phone
</label>
<div class="row margin-bottom-20">
<div class="col-md-6 col-md-offset-0">
<input class="form-control" type="text" name="phone">
</div>
</div>
<label>Message</label> <span class="color-red">*</span>
<div class="row margin-bottom-20">
<div class="col-md-8 col-md-offset-0">
<textarea rows="8" class="form-control" name="message"></textarea>
</div>
</div>
<div class="g-recaptcha" data-sitekey="MYSITEKEYFROMGOOGLE"></div>
<p>
<button type="submit" class="btn btn-primary" name="ContactButton">Send Message</button>
</p>
</form>
This goes at the very top of the page where the form is located:
<?php
if (isset($_POST['ContactButoon'])) {
$url = 'https://google.com/recaptcha/api/siteverify';
$privatekey = "MYPRIVATEKEYFROMGOOGLE";
$response = file_get_contents($url . "?secret=" . $privatekey . "&response=" . $_POST['g-recaptcha-response'] . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
$date = json_decode($response);
if (isset($data->success) AND $data->success == true) {
header('Location: contact.php?CaptchaPasss=True');
} else {
header('Location: contact.php?CaptchaFail=True');
}
}
?>
And this is the forms functionality:
// Receiving variables
#$pfw_ip = $_SERVER['REMOTE_ADDR'];
#$name = addslashes($_GET['name']);
#$email = addslashes($_GET['email']);
#$phone = addslashes($_GET['phone']);
#$message = addslashes($_GET['message']);
// Validation
if (strlen($name) == 0) {
header("Location: http://vmobileautoglass.com/php/err_name.php");
exit;
}
if (strlen($email) == 0) {
header("Location: http://vmobileautoglass.com/php/err_email.php");
exit;
}
if (strlen($message) == 0) {
header("Location: http://vmobileautoglass.com/php/err_message.php");
exit;
}
//Sending Email to form owner
$pfw_header = "From: $email\n"
. "Reply-To: $email\n";
$pfw_subject = "vMobile Contact Form";
$pfw_email_to = "vmobileag#gmail.com";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "name: $name\n"
. "email: $email\n"
. "phone: $phone\n"
. "message: $message\n";
#mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header);
header("Location: http://vmobileautoglass.com/php/successform.php");
You have a typo:
$date = json_decode($response);
if(isset($data->success) AND $data->success==true){
$date should be $data.

PHP file only capturing certain data from HTML form

Thank you in advance for your assistance.
I am struggling to get all the information within this form to print properly to email. At present I am receiving data from the 'email', 'checkin' and 'checkout' input fields. However 'name' , 'guests' and 'message' do not appear.
This is the HTML code for the form:
<form class="reservation-vertical clearfix" role="form" method="post" action="php/reservation.php" name="reservationform" id="reservationform">
<div id="message"></div>
<!-- Error message display -->
<div class="form-group">
<label for="name"><span class="required">*</span> Your Name</label>
<input name="name" type="text" class="form-control" value="" placeholder="Full Name"/>
</div>
<div class="form-group">
<label for="email">E-mail</label>
<input name="email" type="text" value="" class="form-control" placeholder="Please enter your E-mail"/>
</div>
<div class="form-group">
<label for="checkin">Check-in</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Check-in is from 2:00pm"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<i class="fa fa-calendar infield"></i>
<input name="checkin" type="text" value="" class="form-control" placeholder="Check-in"/>
</div>
<div class="form-group">
<label for="checkout">Check-out</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Check-out is by 11:00am"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<i class="fa fa-calendar infield"></i>
<input name="checkout" type="text" value="" class="form-control" placeholder="Check-out"/>
</div>
<div class="form-group">
<label for="guests">Guests</label>
<i class="fa fa-user infield"></i>
<input name="guests" type="text" value="" class="form-control" placeholder="Number of guests"/>
</div>
<div class="form-group">
<label for="extra"> Your message</label>
<textarea name="extra" rows="9" class="form-control"></textarea>
</div>
<button type="submit" class="btn btn-primary btn-block">Enquire Now</button>
</div>
</div>
</div>
</form>
Here is the PHP code:
<?php
if(!$_POST) exit;
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
$guests = $_POST['guests'];
$extra = $_POST['extra'];
if(get_magic_quotes_gpc()) {
$extra = stripslashes($extra);
$email = stripslashes($email);
$name = stripslashes($name);
$guests = stripslashes($guests);
}
$address = "myemail#gmail.com";
$e_subject = "Hotel booking enquiry submitted by $fullname" . PHP_EOL;
$e_body = "
A hotel booking enquiry has been made by: $name
Their email is: $email
The customer wants to check-in at: $checkin
and check-out at: $checkout
The customer requested accommodation for: $guests guest(s).
They also included this message: $extra" . PHP_EOL;
$e_reply = "You can contact the customer via email, $email";
$msg = wordwrap( $e_body . $e_reply, 70 );
$headers = "From: myemail#gmail.com\r\n" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id=success_page style=text-align:center>";
echo "<h4>Booking enquiry sent successfully!</h4>";
echo "<p><br>Thank you, your enquiry has been received. We will contact you shortly to complete your booking.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo "ERROR!";
}
This line
$e_subject = "Hotel booking enquiry submitted by $fullname" . PHP_EOL;
Should be
$e_subject = "Hotel booking enquiry submitted by $name" . PHP_EOL;

Select a select value to send in emailscript

I am trying to get a mail script to work (well, it's working except for one part). I added a dropdown menu, but for some reason it's value is empty when reading the mail that was sent.
The dropdown menu that I got:
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Type werkzaamheden</label>
<select type="select" id="select" name="select">
<option value="kameronderhoud">kameronderhoud</option>
<option value="glas-bewassing">glas-bewassing</option>
<option value="specialistisch reinigen">specialistisch reinigen</option>
<option value="vloer-onderhoud">vloer-onderhoud</option>
<option value="woningontruiming">woningontruiming</option>
<option value="gevel-onderhoud">gevel-onderhoud</option>
<option value="overige">overige</option>
</select>
</div>
</div>
</div>
These are my POSTS:
$tel = $_POST['phone'];
$name = $_POST['name'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$select = $_POST['select'];
$comments = $_POST['comments'];
$phone = $_POST['phone'];
All of them work except select.
Edit: here is the full form
$e_body = "Er is contact opgenomen door $name." . PHP_EOL . PHP_EOL;
$e_content = "<br><br>
Gegevens:<br>
Naam: $name <br>
E-mail: $email <br>
Tel: $phone <br>
Type: $select <br>
$commentsb<br> " . PHP_EOL . PHP_EOL;
$e_reply = " $email2";
Everything displays correctly except the select part. Anybody know what could be causing that?
If it's needed, here is a working part of the form (HTML):
<form method="post" id="contactform" name="contactform" class="contact-form" action="mail/contact.php" type="contact">
<div class="col-md-12">
<h2 class="short">Vraag een <strong>Offerte</strong> aan</h2>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Uw naam*</label>
<input type="text" id="name" name="name" class="form-control input-lg" placeholder="">
</div>
<div class="col-md-6">
<label>Uw mail*</label>
<input type="email" id="email" name="email" class="form-control input-lg" placeholder="">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Type werkzaamheden</label>
<select type="select" id="select" name="select">
<option value="kameronderhoud">kameronderhoud</option>
<option value="glas-bewassing">glas-bewassing</option>
<option value="specialistisch reinigen">specialistisch reinigen</option>
<option value="vloer-onderhoud">vloer-onderhoud</option>
<option value="woningontruiming">woningontruiming</option>
<option value="gevel-onderhoud">gevel-onderhoud</option>
<option value="overige">overige</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Uw telefoonnummer</label>
<input type="text" id="phone" name="phone" class="form-control input-lg" placeholder="">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Onderwerp</label>
<input type="text" id="email2" name="email2" class="form-control input-lg" placeholder="">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Bericht</label>
<textarea cols="6" rows="7" id="comments" name="comments" class="form-control input-lg" placeholder=""></textarea>
</div>
</div>
</div>
<div class="col-md-12">
<input id="submit" name="submit" type="submit" class="btn btn-primary btn-lg pull-right" value="Verstuur">
</div>
</div>
</form>
PHP script:
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$tel = $_POST['phone'];
$name = $_POST['name'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$select = $_POST['select'];
$comments = $_POST['comments'];
$phone = $_POST['phone'];
if ($_POST['form_type'] == 'contact'){
}else{
if(trim($name) == '') {
echo '<div style="color:red;border:solid 1px red;" class="alert alert-error">Vul uw naam in.</div>';
exit();
} else if(trim($email) == '') {
echo '<div style="color:red;border:solid 1px red;" class="alert alert-error">Vul uw email adres in.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div style="color:red;border:solid 1px red;" class="alert alert-error">Vul een geldige emailadres in.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div style="color:red;border:solid 1px red;" class="alert alert-error">Vul uw telefoonnummer in.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
//$address = "example#themeforest.net";
$address = "*email*";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
if ($_POST['form_type'] == 'contact'){
$e_subject = 'Terugbelafspraak';
}else{
$e_subject = 'Contact Form';
}
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
if ($_POST['form_type'] == 'contact'){
$e_body = "Er is een terugbelverzoek gemaakt." . PHP_EOL . PHP_EOL;
$e_content = "" . PHP_EOL . PHP_EOL;
$e_reply = "Nummer: $tel";
}else{
if($comments == ''){
$commentsb = '';
}else{
$commentsb = 'Bericht:'.$comments.'';
}
$e_body = "Er is contact opgenomen door $name." . PHP_EOL . PHP_EOL;
$e_content = "<br><br>
Gegevens:<br>
Naam: $name <br>
E-mail: $email <br>
Tel: $phone <br>
Type: $select <br>
$commentsb<br> " . PHP_EOL . PHP_EOL;
$e_reply = " $email2";
}
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: *email*" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/html; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
if ($_POST['form_type'] == 'contact'){
echo "<div class='alert alert-success'>";
echo "<h3 style='text-transform:none;'>Aanvraag is verzonden.</h3><br>";
echo "<p>Er zal zo spoedig mogelijk contact opgenomen worden door ons.</p>";
echo "</div>";
}
if ($_POST['form_type'] != 'contact'){
echo "<div class='alert alert-success'>";
echo "<h3 style='text-transform:none;'>Email is verzonden.</h3><br>";
echo "<p>Bedankt <strong>$name</strong>, uw mail is ontvangen door sfsdf.</p>";
echo "</div>";
}
} else {
echo 'ERROR!';
}

Can't get my php form working, sends mail but doesn't run code on redirect page

This question gets asked all the time, but I can't figure out why mine isn't working. I have a form that redirects to itself. If PHP decides it is submitted, there is a success/failure message and it displays the user input as the default value and disables the fields: using phpinfo I can see that the form is being submitted, but this first conditional doesn't work. I've tried a couple of versions, but no luck. It's weird because it sends the email
Specifically, the result and disable functions don't display their code after the form has been sent.
<?php
function clean($data) {
$data = trim(stripslashes(strip_tags($data)));
return $data;
}
function result(){
if($sent) echo $result;
}
function disable($field){
if($sent){
if($field != null){
$ret .= $field . '", disabled, placeholder!="';
}
$ret .= '", disabled, placeholder!="';
echo $ret;
}
}
function option($item){
$ret = "<option>";
if($sent){
if($eventType == $item){
$ret = "<option selected>";
}
}
$ret .= $item . "</option>";
echo $ret;
}
if(isset($_POST['name'])){
$sent = TRUE;
$result = null;
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$eventDate = $_POST['eventDate'];
$eventTime = $_POST['eventTime'];
$eventLength = $_POST['eventLength'];
$eventLocation = $_POST['eventLocation'];
$eventType = $_POST['eventType'];
$message = $_POST['message'];
$recipient = "";
$subject = " Form Submission";
$mailheader = "From: \r\n";
$formcontents = "You received this e-mail message through your website: \n\n";
$formcontents .= "Name: " . clean($name) . "\r\n";
$formcontents .= "Phone: " . clean($phone) . "\r\n";
$formcontents .= "Email: " . clean($email) . "\r\n";
$formcontents .= "Event Date: " . clean($eventDate) . "\r\n";
$formcontents .= "Event Time: " . clean($eventTime) . "\r\n";
$formcontents .= "Event Length: " . clean($eventLength) . "\r\n";
$formcontents .= "Event Location: " . clean($eventLocation) . "\r\n";
$formcontents .= "Event Type: " . clean($eventType) . "\r\n";
$formcontents .= "Message: " . clean($message) . "\r\n";
$formcontents .= "\r\n";
$formcontents .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
$formcontents .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
// Send mail
if(mail($recipient, $subject, $formcontents, $mailheader)){;
$result = '<h3 class="alert alert-success"> Thank you, your form was successfully sent and I will contact you shortly.</h3>';
} else {
$result = '<h3 class="alert alert-error"> Your mail could not be sent at this time.</h3>';
}
}
?>
<form action="contact.php" method="POST" class="form-horizontal span4">
<fieldset>
<legend>
<h2>Or send me a message. </h2>
</legend>
<p class="help-block">None of the fields are required, but the more information I have about your event, the more detailed I can be in my response.</p>
<legend class="help-block">Your Details</legend>
<div class="control-group">
<label for="name" class="control-label">Your Name</label>
<div class="controls">
<input id="name" type="text" name="name" placeholder="<?php disable($name); ?>" class="input-xlarge"/>
</div>
</div>
<div class="control-group">
<label for="phone" class="control-label">Your Contact Number</label>
<div class="controls">
<input id="phone" type="tel" name="phone" placeholder="<?php disable($phone); ?>" class="input-xlarge"/>
</div>
</div>
<div class="control-group">
<label for="email" class="control-label">Your Email</label>
<div class="controls">
<input id="email" type="email" name="email" placeholder="<?php disable($email); ?>" class="input-xlarge"/>
</div>
</div>
<legend class="help-block">Your Event </legend>
<div class="control-group">
<label for="eventDate" class="control-label">Your Event's Date</label>
<div class="controls">
<input id="eventDate" type="date" name="eventDate" placeholder="<?php disable($eventDate); ?>" class="input-xlarge"/>
</div>
</div>
<div class="control-group">
<label for="eventTime" class="control-label">Your Event's Start Time</label>
<div class="controls">
<input id="eventTime" type="time" name="eventTime" placeholder="<?php disable($eventTime); ?>" class="input-xlarge"/>
</div>
</div>
<div class="control-group">
<label for="eventLength" class="control-label">Your Event's Length</label>
<div class="controls">
<input id="eventLength" type="text" name="eventLength" placeholder="<?php disable($eventLength); ?>" class="input-xlarge"/>
</div>
</div>
<div class="control-group">
<label for="eventLocation" class="control-label">Your Event's Location</label>
<div class="controls">
<input id="eventLocation" type="text" name="eventLocation" placeholder="<?php disable($eventLocation); ?>" class="input-xlarge"/>
</div>
</div>
<div class="control-group">
<label for="eventType" class="control-label">What Kind of Event</label>
<div class="controls">
<select id="eventType" name="eventType" placeholder="<?php disable($eventType); ?>"><?php option("Charity Event"); option("Expo/Trade Show"); option("Personal Event"); option("Other"); ?></select>
</div>
</div>
<div class="control-group">
<label for="message" class="control-label">Other comments or the best time to reach you.</label>
<div class="controls">
<textarea id="message" name="message" rows="10" placeholder="<?php disable($message); ?>" class="input-xxlarge"></textarea>
</div>
</div>
<div class="form-actions">
<button type="submit" name="submit" placeholder="<?php disable(null); ?>" class="btn btn-primary">Send Message</button>
</div>
</fieldset>
</form>
You have to import your global variables into function scope, like:
function result(){
global $sent, $result;
if($sent) echo $result;
}
..in functions disable() and option(), too.
if(isset($_POST['name'])){
should be
if(isset($_POST['submit'])){

Categories