Hi I have the same issue. Just want to print out the value that was selected on the calendar and include it to send to my email. It prints out to the page but it does not include to the email.
PHP code:
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Attendance Form";
$date = $_POST['date[]'];
$message = "Bro./Sis. ".$name." "."attendance will be at"." ".print_r(date($date['d,m,Y']));
$emailTo = "me#domain.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if (mail($emailTo, $subject, $date, $mailHeaders)) {
$message ='<div class="alert alert-success d-inline-block" role="alert">Your message has been sent.</div>';
$type = "success";
} else {
$error = '<div class="alert alert-danger d-inline-block" role="alert">Something went wrong, please try again.</div>';
}
}
?>
Hi guys thank you for your comments. I used the datepicker but whenever I use the jqueryui i cannot pick the value so i put the date as a type. This is my HTML:
<div class="container-fluid text-center" id="attendform" style="top: 50%;transform: translateY(25%) !important;position: relative;">
<!--Form for join us-->
<div class="container bg-light p-5 mt-5 d-inline-block text-center">
<h2 class="join-title text-center display-4 mb-0">Join us!</h2><br><br>
<div class="mt-0 mb-3" id="error"><? echo $error.$message; ?></div>
<div class="container text-center">
<form class="" method="post">
<label for="name" class="text-dark border-top-0 border-right-0 border-left-0" >Name: </label> <br>
<input class="form-control" type="text" name="name" id="name" placeholder="Bro./Sis."><br>
<label for="email">Email</label>
<input type="email" name="email" class="form-control" id="email" placeholder="user#domain.com" required> <br>
<!---->
<label for="date" class="d-inline-block">Date: </label>
<input type="date" id="datepicker" name="date[]" class="form-control" value=""></input><br>
<input class="btn btn-dark" id="sendbtn" type="submit" name="send" value="Send">
</form>
</div>
</div>
</div>
</div>
I disable the jquery datepicker first and try with the normal calendar
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<!--script-->
<script src="js/jquery-3.4.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js" integrity="sha256-0YPKAwZP7Mp3ALMRVB2i8GXeEndvCq3eSl/WsAl1Ryk=" crossorigin="anonymous"></script>
<!-- <script type="text/javascript">
$(function() {
$("#datepicker").datepicker();
});
</script> -->
I finally figure the answer:
PHP code
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Attendance Form";
$date = $_POST['date'];
$member = $_POST['member'];
$message = "Bro./Sis. ".$name." "."($member)"."\n\n"."Schedule:"." "."($date)";
$emailTo = "me#domain.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if (mail($emailTo, $subject, $message, $mailHeaders)) {
$message ='<div class="alert alert-success d-inline-block" role="alert">Your message has been sent.</div>';
$type = "success";
} else {
$error = '<div class="alert alert-danger d-inline-block" role="alert">Something went wrong, please try again.</div>';
}
}
?>
I edited my form and put the jquery datepicker
<form class="" method="post">
<label for="name" class="text-dark border-top-0 border-right-0 border-left-0" >Name: </label> <br>
<input class="form-control" type="text" name="name" id="name" placeholder="Bro./Sis."><br>
<label for="email">Email</label>
<input type="email" name="email" class="form-control" id="email" placeholder="user#domain.com" required> <br>
<!---->
<label for="date" class="d-inline-block">Date: </label>
<input type="text" id="datepicker" name="date" class="form-control" value=""></input><br>
<p>Are you already a member of the youth?</p>
<label for=member>
<input type="radio" name="member" value="Yes member">Yes
<input type="radio" name="member" value="Non member">No
</select><br><br>
<input class="btn btn-dark" id="sendbtn" type="submit" name="send" value="Send">
</form>
Related
I have a simple contact form, the html is this part:
<!-- CONTACT FORM -->
<form id="contact-form" name="contactform" class="row">
<!-- CONTACT FORM IMPUT -->
<div id="input_name" class="col-md-12">
<input type="text" name="name" id="name" class="form-control" placeholder="Il tuo nome">
</div>
<div id="input_email" class="col-md-12">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
</div>
<div id="input_subject" class="col-md-12">
<input type="text" name="subject" id="subject" class="form-control" placeholder="Numero di telefono">
</div>
<div id="input_message" class="col-md-12">
<textarea class="form-control" name="message" id="message" rows="6" placeholder="Il tuo messaggio..."></textarea>
</div>
<div class="col-md-12 sinistra"><br>Quale servizio ti interessa?<br><br></div>
<div class="col-md-4 sinistra">
<input type="radio" name="tipologia" value="standard"> Standard<br>
</div>
<div class="col-md-4 sinistra">
<input type="radio" name="tipologia" value="avanzato"> Avanzato<br>
</div>
<div class="col-md-4 sinistra">
<input type="radio" name="tipologia" value="deluxe"> Deluxe<br>
</div>
<div class="col-md-12"><br></div>
<!-- CONTACT FORM SUBMIT BUTTON -->
<div id="form_btn" class="col-md-12">
<input type="submit" value="Invia" id="submit" class="btn btn-small btn-blue">
</div>
<!-- CONTACT FORM MESSAGE -->
<div class="col-md-12 contact-form-msg">
<span class="loading"></span>
</div>
</form>
with this php file
<?
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$subject = $_REQUEST["subject"];
$msg = $_POST["msg"];
$tipologia = $_POST['tipologia'] ;
$to = "info#gmail.com";
if (isset($email) && isset($name) && isset($msg) ) {
$email_subject = "$name ha inviato una richiesta di ordine";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "Da: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg = "Da: $name<br/> Email: $email <br/> Telefono: $subject <br/>
Tipologia: $tipologia <br/> Messaggio: $msg";
$mail = mail($to, $email_subject, $msg, $headers);
if($mail)
{
echo 'success';
}
else
{
echo 'failed';
}
}
?>
but I have a problem with radio input, the form works but doesn't pass the value of radio to email, so the email has the Tipologia without the radio selected for the form... What could be the error?
<form> defaults to a GET method if POST isn't implied.
You're using two POST arrays.
So... use a POST method and all POST arrays.
Either way, everything must match.
You should also check if the radio buttons are set or not, or any other you wish to include.
I am trying to create a two page form- the first page is optional. Its a prompt to get started. It was working perfectly until I started adding in PHPMailer. Now when I click submit on the first, optional form on the first page it submits it through the mailer and all its validations/errors then emails correctly it if I comment out the error if statements.
Here is the first form that is optional. It should take you to the estimate page with those values stored in the form already so you don't have to do it over again.
<form class="form-horizontal first-form" action="estimate.php" method="post">
<div class="form-group">
<label for="inputMoveDate" class="col-xs-4 text-left">Move Date</label>
<div class="col-xs-8">
<input type="text" name="date" class="form-control" id="datepicker">
</div><!--col-xs-7-->
</div><!--form-group-->
<div class="form-group">
<label for="pickUpZip" class="col-xs-4">Pick Up Zip</label>
<div class="col-xs-8">
<input type="text" name="pickUpZip" class="form-control" id="pickUpZip" placeholder="">
</div><!--col-xs-7-->
</div><!--form-group-->
<div class="form-group">
<label for="dropOffZip" class="col-xs-4">Drop Off Zip</label>
<div class="col-xs-8">
<input type="text" name="dropOffZip" class="form-control" id="dropOffZip" placeholder="">
</div><!--col-xs-7-->
</div><!--form-group-->
<div class="form-group">
<div class="col-xs-12">
<button type="submit" class="btn btn-default center-block">Continue</button>
</div><!--col-sm-offset-2-->
</div><!--form-group-->
</form>
Estimate.php second page. The PHP at the top of the document.
session_start();
if ($_SERVER["REQUEST_METHOD"]=="POST") {
$date = $_POST['date'];
$pickUpZip = $_POST['pickUpZip'];
$dropOffZip = $_POST['dropOffZip'];
$dwellingType = $_POST['dwellingType'];
$salutation = $_POST['salutation'];
$firstName = trim(filter_input(INPUT_POST, "first-name", FILTER_SANITIZE_STRING));
$lastName = trim(filter_input(INPUT_POST, "last-name", FILTER_SANITIZE_STRING));
$email = trim(filter_input(INPUT_POST, "email", FILTER_SANITIZE_SPECIAL_CHARS));
$phone = $_POST['phone'];
$pickUpAddress = $_POST['pickUpAddress'];
$pickUpCity = $_POST['pickUpCity'];
$pickUpState = $_POST['pickUpState'];
$comments = $_POST['comments'];
$emailBody ="From: $salutation $firstName $lastName\n
Phone Number: $phone\n
E-Mail: $email\n
Message:\n $comments
\n \n
Move Date: $date\n
Pick Up Address: $pickUpAddress\n
Pick Up City: $pickUpCity\n
Pick Up State: $pickUpState\n
Pick Up Zip: $pickUpZip\n
\n
Drop Off Zip: $dropOffZip\n
Dwelling Type: $dwellingType\n";
if($firstName == "" || $email == "" || $lastName == "") {
echo "Please fill in the required forms: first name, last name, and email.";
exit;
}
if ($_POST["address"] != "") {
echo "Bad form input";
exit;
}
require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer;
if (!$mail->ValidateAddress($email)) {
echo 'Invalid email. Try again.';
exit;
}
$mail->setFrom($email, $firstName);
$mail->addAddress('xxxx#xxx.com', 'name here');
$mail->isHTML(false);
$mail->Subject = 'Estimate Request Inquiry From ' . $firstName;
$mail->Body = $emailBody;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
header("location:estimate.php?status=thanks");
}
Here is the starting and ending of the form HTML, the highlights.
<?PHP
if (isset($_GET["status"]) && $_GET["status"] == "thanks") {
echo "Thank you for your estimate request. We will return your inquiry soon!
</div>";
} else {
?>
<form class="form-horizontal first-form" action="estimate.php" method="post" style="margin: 0 45px;">
<label for="date" class="col-xs-4 text-left">Move Date</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="datepicker" name="date" value="<?php echo $_POST["date"]; ?>">
</div><!--col-xs-7-->
</div><!--form-group-->
<div class="form-group">
<label for="pickUpZip" class="col-xs-4">Pick Up Zip</label>
<div class="col-xs-8">
<input type="text" name="pickUpZip" class="form-control" id="pickUpZip" value="<?php echo $_POST["pickUpZip"]; ?>">
</div><!--col-xs-7-->
</div><!--form-group-->
<div class="form-group">
<label for="dropOffZip" class="col-xs-4">Drop Off Zip</label>
<div class="col-xs-8">
<input type="text" name="dropOffZip" class="form-control" id="dropOffZip" value="<?php echo $_POST["dropOffZip"]; ?>">
</div><!--col-xs-7-->
</div><!--form-group-->
<div class="col-xs-12">
<button type="submit" id="submit" name="submit" class="btn btn-default center-block">Submit</button>
</div><!--col-sm-offset-2-->
</div><!--form-group-->
</form>
<?PHP
}
?>
This line attempts to send the email every time:
if(!$mail->send()) {
and your error messages are echoed if and when it fails.
You should nest this entire block in an if statement that checks if the form was submitted from page 2. You can give the submit button a different value and check that (i.e. 'submit1', 'submit2').
I am using bootstrap to open up a modal form.
I really cannot figure out what is going on. This code works in other projects (http://phpform.webitwebsites.co.nz/newtest/) and sends the mail no problem. But if I copy it into my website, it is like my submit button is unresponsive and it doesn't load the initiate quote.php file.
Here is a live version where it is not working
http://phpform.webitwebsites.co.nz/test/
My HTML:
<button href="#freeQuote" role="button" data-toggle="modal" type="button" class="btn btn-primary btn-lg outline" style="font-size:16px;">Free Quote</button>
</center>
<div class="modal fade" id="freeQuote">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">FREE Quote</h3>
</div>
<!-- close modal-header -->
<div class="modal-body">
<h4>Send us a description </h4>
<hr>
<form name="contact" method="post" action="quote.php">
<label for="name">Your Name</label>
<br>
<input class="col-md-10" type="text" name="name" class="input-xlarge">
<br>
<br>
<label for="company">Your Company</label>
<br>
<input class="col-md-10" type="text" name="company" class="input-xlarge">
<br>
<br>
<label for="email">Your E-mail</label>
<br>
<input class="col-md-10" type="email" name="email" class="input-xlarge">
<br>
<br>
<label for="message">Details</label>
<br>
<textarea class="col-md-10" name="message" class="input-xlarge"></textarea>
<br>
<input class="btn-sm btn-success" type="submit" value="Send!" id="submit">
</form>
</div>
<!-- close modal-body -->
My PHP
<?php
$myemail = 'example#gmail.com';
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$company = strip_tags ($_POST['company']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Name:</strong> ".$name."<br>";
echo "<strong>Company:</strong> " .$company . "<br>";
echo "<stong>Email:</strong> ".$email."<br>";
echo "<stong>Message:</strong> ".$message."<br>";
//generate email and send!
$to = $myemail;
$email_subject = "New Quote form submission";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
}
?>
I'm currently using an html5 website with a contact form and a php action to receive contact emails. I've tried a few different codes in my php but non have stopped the blank emails from coming. I do have google analytics enables on my code but have blocked the crawler through robot.txt. Here is my code.
PHP CODE
<?php
foreach ($_GET as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
}
}
$name = trim(htmlentities($_GET['name'],ENT_QUOTES,'utf-8'));
$email = trim(htmlentities($_GET['email'],ENT_QUOTES,'utf-8'));
$phone = trim(htmlentities($_GET['phone'],ENT_QUOTES,'utf-8'));
$messages = trim(htmlentities($_REQUEST['messages'],ENT_QUOTES,'utf-8'));
if (strlen($name) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
if (strlen($email) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
$to = "junior.8791#gmail.com";
$message = "Name: ".$name;
$message.="\n\nEmail: ".$email;
$message.="\n\nPhone: ".$phone;
$message .= "\n\nMessage: ".$messages;
$headers = "From: $email";
$headers .="\nReply-To: $email";
$success = mail($to, $subject, $message, $headers);
if ($success) {
echo "<script>window.location = 'http://www.mason372.org/thankyou.html'</script>";
} else {
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
?>
CONTACT FORM
<form action="email.php" method="post" id="form">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" class="name" name="name" id="name" placeholder="Name" value="" aria-describedby="name-format" required aria-required=”true” pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" title="e.g.'John Doe'" required="" />
</div>
<div class="6u">
<input type="email" class="email" name="email" id="email" placeholder="Email" required="" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="tel" class="tel" name="phone" id="phone" name="phone" type="text" placeholder="Phone Number" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" required />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="messages" id="messages" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message">
<input type="reset" class="button button-alt" value="Clear Form">
I am using a simple html form as a contact, and when fields and submitted the form does not clear the fields.
this is my php
I read online in few places and I've learned that I have to use the .reset , but I am not familiar with php a lot. I am not sure where would I add the .reset and how.
<?
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$msg = $_REQUEST["msg"];
$to = "example#example.com";
if (isset($email) && isset($name) && isset($msg)) {
$subject = "Message / Closure Film";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg = "Name: $name:<br/> Email: $email <br/> Message: $msg";
$mail = mail($to, $subject, $msg, $headers);
if($mail)
{
echo 'success';
}
else
{
echo 'failed';
}
}
?>
my html
<div id="contact">
<div class="container">
<div class="row-fluid PageHead">
<div class="span12">
<h3>CONTACT US<span> <img src="images/underline.png" alt="______"></span></h3>
</div>
</div>
<div class="row-fluid ContactUs">
<div class="span6 offset3">
<form class="form-horizontal" id="phpcontactform">
<div class="control-group">
<input class="input-block-level" type="text" placeholder="Full Name" name="name" id="name">
</div>
<div class="control-group">
<input class="input-block-level" type="email" placeholder="Email" name="email" id="email">
</div>
<div class="control-group">
<textarea class="input-block-level" rows="10" name="message" placeholder="Your Message" id="message"></textarea>
</div>
<div class="control-group">
<p>
<input class="btn btn-danger btn-large" type="submit" value="Send Message">
</p>
<span class="loading"></span> </div>
</form>
</div>
added this to the head of my html, but didnt get any result
<script type="javascript">
$('#phpcontactform').trigger("reset");
</script>
Try:
<script type="javascript">
$(document).ready(function() {
$('#phpcontactform')[0].reset();
});
</script>
I'm not sure if you're trying to do an ajax submit and keep the user on the page, or just submit the form. But the line you're looking for is $("#phpcontactform")[0].reset();, you could wrap that in a $(document).ready() if you needed to!