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;
Related
I was trying to write contact form using HTML & PHP, it was working fine when I was testing the code with input type="submit" name="submit" value="Submit"
But while using div & button class:"" it's not working for me.
Can someone help me?
MY PHP CODE
<? php
if(isset($_POST['submit']))
{
$to = "example#gmail.com";
$from = $_POST['email'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone =$_POST['phone'];
$subject = "Enquiry From".$name;
$subject2 = "Copy of your Enquiry";
$message = $name . " " . "wrote the following:" . "\n\n" . $_POST['message'] ."Contact Details:" . "\n\n" .$_POST['email'] . $_POST['phone'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
===========================
HTML FORM CODE
<div class="container-contact100">
<div class="wrap-contact100">
<form class="contact100-form validate-form" action="mail.php" method="post">
<span class="contact100-form-title">
Feel free to reach us
</span>
<div class="wrap-input100 validate-input" data-validate="Please enter your name">
<input class="input100" type="text" name="name" placeholder="Full Name">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input" data-validate = "Please enter your email: e#a.x">
<input class="input100" type="text" name="email" placeholder="E-mail">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input" data-validate = "Please enter your phone">
<input class="input100" type="number" name="phone" placeholder="Phone">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input" data-validate = "Please enter your Subject">
<input class="input100" type="text" name="subject" placeholder="Subject">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input" data-validate = "Please enter your message">
<textarea class="input100" name="message" placeholder="Your Message"></textarea>
<span class="focus-input100"></span>
</div>
<div class="container-contact100-form-btn">
<button type="submit" class="contact100-form-btn" type="submit">
<span>
<i class="fa fa-paper-plane-o m-r-6" aria-hidden="true"></i>
Send
</span>
</button>
</div>
</form>
</div>
</div>
<div id="dropDownSelect1"></div>
Use
if(isset($_POST['email']))
Why?
You don’t have any element whose name is submit.
You repeated type=“submit” twice
When I try to click sent button, the content from the webpage is not redirecting to the .php page.I am using recaptcha in the form .Can you please help me to solve this issue..
my HTML code is:
<form action="sendform.php" id="contact-form" class="form-horizontal"
method="post">
<fieldset>
<div class="form-group">
<label class="col-sm-4 control-label" for="name">Your Name</label>
<div class="col-sm-8">
<input type="text" placeholder="Your Name" class="form-control" name="name" id="name">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="email">Email Address</label>
<div class="col-sm-8">
<input type="text" placeholder="Enter Your Email Address" class="form-control" name="email" id="email">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="subject">Subject</label>
<div class="col-sm-8">
<input type="text" placeholder="Subject" class="form-control" name="subject" id="subject" list="exampleList">
<datalist id="exampleList" >
<option value="a">A</option>
<option value="b">B Combo</option>
</datalist>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="message">Your Message</label>
<div class="col-sm-8">
<textarea placeholder="Please Type Your Message" class="form-control" name="message" id="message" rows="3"></textarea>
</div>
</div>
<div class="col-sm-8" class="form-group" class="g-recaptcha" data-sitekey="xxxxxxyyyyyyy"></div>
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l">Submit</button>
<button type="reset" class="btn btn-primary">Cancel</button>
</div>
</fieldset>
</form>
And my PHP Code sendform.php
<?php
if (isset($_POST['submit']) && !empty($_POST['submit'])):
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
//your site secret key
$secret = 'xxxxxxxxxxxxx';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if ($responseData->success):
$to = "aaa#abc.com"; // this is your Email address
$from = !empty($_POST['email']) ? $_POST['email'] : ''; // this is the sender's Email address
$name = !empty($_POST['name']) ? $_POST['name'] : '';
$subject = !empty($_POST['subject']) ? $_POST['subject'] : '';
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = "From:" . $from;
$headers .= 'From:' . $name . ' <' . $from . '>' . "\r\n";
$headers2 = "From:" . $to;
mail($to, $subject, $message, $headers);
$succMsg = 'Your request have submitted successfully.';
else:
$errMsg = 'Robot verification failed, please try again.';
endif;
else:
$errMsg = 'Please click on the reCAPTCHA box.';
endif;
else:
$errMsg = '';
$succMsg = '';
endif;
?>
I have tested your code and it works.
Please make sure that you have placed your html and php files in same directory and also your files should be served via a local running server.
So your url should look like this http://localhost/testing/index.html
Although, your sendform.php gives me captcha error ofcourse.
"Please click on the reCAPTCHA box."
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.
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!';
}
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'])){