Select a select value to send in emailscript - php

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!';
}

Related

Contact form (Bootstrap, html & php)

I just made my contact form to function, sort of. It has a few issues:
When the form is sent, it kicks you off the page, directs you to a blank page with the message: "Thank you etc". I would love to stay on the page, and just either get a box pop-up with the success message or just have it on the page. Either is fine :)
The error message doesn't show, it just puts you on a blank page.
The errMessages like "please fill in a valid e-mail" don't show. Probably because I removed the labels, but I would like to show that message IN the box rather than under it.
It's overriding my CSS! But that happens sometimes on my computer, one time I see lines other times I see boxes. So that issue might be somewhere else. However with the 'working form' it changes my last box.
This is what I meant with changing CSS on my boxes
PHP code:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'Demo Contact Form';
$to = 'denise#hetfulfilmentbedrijf.nl';
$subject = 'Message from Contact Demo';
$body = "From: $name\n Subject: $subject\n Number: $phone\n E-Mail: $email\n Message:\n $message";
//Check if name has been entered
if(!$_POST['name']) {
$errName = 'Vul alsjeblieft je naam in';
}
//Check if subject has been entered
if(!$_POST['subject']) {
$errName = 'Vul alsjeblieft een onderwerp in';
}
//Check if number has been entered
if(!$_POST['phone']) {
$errName = 'Vul alsjeblieft je nummer in';
}
//Check if e-mail is entered and valid
if(!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Vul alsjeblieft je e-mailadres in';
}
//Check if message has been entered
if(!$_POST['email']) {
$errMessage = 'Laat alsjeblieft een bericht achter';
}
// If no errors, send email
if (!$errName && !$errSubject && !$errPhone && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
echo $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
}
else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
HTML:
<form class="form-horizontal" role="form" method="post" action="partials/contactform.php">
<div class="form-group offset-top-45">
<textarea rows="11" cols="100" class="form-control" id="message" name="message" placeholder="Laat hier je bericht voor ons achter:"></textarea><?php echo htmlspecialchars($_POST['message']);?></textarea>
<span class="help-block" style="display: none;">Laat alsjeblieft een bericht achter</span>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
</div>
<div class="col-md-6">
<div class="row offset-top-10">
<div class="pull-right">
<img height="60" width="100" src="/images/stamp.png" alt="stamp">
</div>
</div>
<div class="row offset-top-10" style="padding-right:20px; padding-left:10px">
<form role="form" id="feedbackForm">
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Hoe heet je?" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<span class="help-block" style="display: none;">Vul alsjeblieft je naam in</span>
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
<div class="form-group">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Wat is het onderwerp?" value="<?php echo htmlspecialchars($_POST['subject']); ?>">
<span class="help-block" style="display: none;">Vul alsjeblieft een onderwerpin</span>
<?php echo "<p class='text-danger'>$errSubject</p>";?>
</div>
<div class="form-group">
<input type="text" class="form-control" id="phone" name="phone" placeholder="Op welk nummer kunnen wij jou bereiken?" value="<?php echo htmlspecialchars($_POST['phone']); ?>">
<span class="help-block" style="display: none;">Vul alsjeblieft je nummer in</span>
<?php echo "<p class='text-danger'>$errPhone</p>";?>
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Wat is je e-mailadres?">
<span class="help-block" style="display: none;">Vul alsjeblieft je e-mail in</span>
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
<div class="form-group">
<div class="col-md-12 text-right">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary btn-s">
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</div>
</div>
</form>
Help is much appreciated!
Full script it should work without any problems
<?php
$result = "";
$errors = ""; //use to count errors
//Error message variables
$errName = "";
$errSubject = "";
$errEmail = "";
$errMessage = "";
//message variables
$name = "";
$subject = "";
$phone = "";
$email = "";
$message = "";
$to = "denise#hetfulfilmentbedrijf.nl";
if (isset($_POST['submit'])) {
//check if name has been entered
if (empty($_POST['name'])) {
$errName = "Vul alsjeblieft je naam in";
$errors++;
} else {
$name = UserInput($_POST['name']);
}
////Check if subject has been entered
if (empty($_POST['subject'])) {
$errSubject = "Vul alsjeblieft een onderwerp in";
$errors++;
} else {
$Subject = UserInput($_POST['subject']);
}
//check if email entered
if (empty($_POST['email'])) {
$errEmail = "Laat alsjeblieft een bericht achter";
$errors++;
} else {
$email = UserInput($_POST['email']);
// check if email is valid
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email)) {
$errEmail = "Vul alsjeblieft je e-mailadres in";
$errors++;
}
}
if (empty($_POST['phone'])) {
$errPhone = "Vul alsjeblieft je nummer in";
$errors++;
} else {
$phone = UserInput($_POST['phone']);
// check if email is numbers
if (!is_numeric($phone)) {
$errPhone = "enter numbers only";
$errors++;
}
}
//check message
if (empty($_POST['message'])) {
$errMessage = "Laat alsjeblieft een bericht achter";
} else {
$message = UserInput($_POST['message']);
}
if ($errors > 0) {
// we have errors do not send email
$result = "<div class=\"alert alert-danger\">Sorry there was an error sending your message. Please fix " . $errors . " errors on the form </div>";
} else {
//no errors set email headers and send email
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <' . $email . '>' . "\r\n";
$body = "<p> New email from $name";
$body .= "<p> Phone : $phone</p>";
$body .= "<p> Email : $email<p>";
$body .= "<p>Message : $message</p>";
if (mail($email, $subject, $msg, $header)) {
$result = "<div class=\"alert alert-success\">Thank You! I will be in touch</div>";
$_POST = array(); //clear the form aftter sendig
} else {
$result = "<div class=\"alert alert-danger\">Sorry there was an error sending your message. Please try again later</div>";
}
}
}
//sanitise use input
function UserInput($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form class="form-horizontal" role="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="form-group">
<div class="col-md-12 text-right">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary btn-s">
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</div>
</div>
<div class="form-group offset-top-45">
<textarea rows="11" cols="100" class="form-control" id="message" name="message" placeholder="Laat hier je bericht voor ons achter:"></textarea><?php if(!empty($_POST['message'])){echo $_POST['message'];}?></textarea>
<?php echo "<p class=\"text-danger\">".$errMessage."</p>";?>
</div>
</div>
<div class="col-md-6">
<div class="row offset-top-10">
<div class="pull-right">
<img height="60" width="100" src="/images/stamp.png" alt="stamp">
</div>
</div>
<div class="row offset-top-10" style="padding-right:20px; padding-left:10px">
<form role="form" id="feedbackForm">
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Hoe heet je?" <?php if(!empty($_POST['name'])){echo "value=\"".$_POST['name']."\"";}?>>
<?php echo "<p class=\"text-danger\">".$errName."</p>";?>
</div>
<div class="form-group">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Wat is het onderwerp?" <?php if(!empty($_POST['Subject'])){echo "value=\"".$_POST['Subject']."\"";}?>>
<?php echo "<p class=\"text-danger\">".$errSubject."</p>";?>
</div>
<div class="form-group">
<input type="text" class="form-control" id="phone" name="phone" placeholder="Op welk nummer kunnen wij jou bereiken?" <?php if(!empty($_POST['phone'])){echo "value=\"".$_POST['phone']."\"";}?>>
<?php echo "<p class=\"text-danger\">".$errPhone."</p>";?>
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Wat is je e-mailadres?">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</form>
Let me know if you have any question or need any help.

Mail sends me a blank message and

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".

Issue with multiple checkboxes in a form

I considered myself fairly adept at PHP and form processing before this. Now I've run into an issue and can't figure it out despite having going over my code time and time again. Naturally I've browsed StackOverflow and followed many examples as closely as I could, but nothing has fixed my issue, so it seems I'm missing something.
The form retrieves checked materials from the user as an array and puts them in an email body, or at least it should.
The HTML form with a checkbox array:
<div id="contact" class="form-container">
<fieldset>
<div id="message"></div>
<form method="post" action="get-quote.php" name="contactform" id="contactform">
<div class="form-group">
<input name="name" id="name" type="text" value="" placeholder="Name" class="form-control">
</div>
<div class="form-group">
<input name="email" id="email" type="text" value="" placeholder="Email" class="form-control">
</div>
<div class="form-group">
<input name="phone" id="phone" type="text" value="" placeholder="Phone" class="form-control">
</div>
<div class="form-group">
<label>Job Type / Material</label>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="sand">
Sand
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="select_fill">
Select Fill
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="common_fill">
Common Fill
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="top_soil">
Top Soil
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="stabilized_sand">
Stabilized Sand
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="crushed_concrete">
Crushed Concrete
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="milled_asphalt">
Milled Asphalt
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="material[]" value="bull_rock">
Bull Rock
</label>
</div>
</div>
<div class="form-group">
<textarea name="comments" id="comments" class="form-control" rows="3" placeholder="Message"></textarea>
<div class="editContent">
<p class="small text-muted"><span class="guardsman">* All fields are required.</span> Once we receive your message we will respond as soon as possible.</p>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit" id="cf-submit" name="submit">Send</button>
</div>
</form>
</fieldset>
</div><!-- /.form-container -->
And the PHP:
<?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");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
if(trim($name) == '') {
echo '<div class="error_message">Please enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">You have entered an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Please enter your message.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$materials = isset($_POST['material']) ? implode(', ', $_POST['material']) : 'none';
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "yourname#yourdomain.com";
$address = "myemail#gmail.com";
// 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.';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
// 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.
$e_body = "You have been contacted by $name from your website, their message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_materials = "They specified the following materials: " . $materials . "." . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name by email, $email or by phone $phone";
$msg = wordwrap( $e_body . $e_content . $e_material . $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/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'>";
echo "<h2>Email Sent Successfully.</h2>";
echo "<p>Thank you <strong>$name</strong>, your message has been sent to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
I didn't build the whole form or email script, I was just asked to get the checkboxes to work. And everything BUT the checkboxes work. Performing a var_dump on $_POST['material'] returns NULL regardless of whether or not boxes are checked.
Any help would be appreciated, as I've gone over this many times without seeing an issue with the code.

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;

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