Contact form within a Boostrap pop-up modal window - php

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);
}
?>

Related

PHP Contact form just.. stopped.. working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 2 years ago.
I had my contact form up and running and I was doing a bit of housekeeping with how it actually looked when it arrived in my inbox. I dunno what I changed but even after reverting it back to when I know it was working it no longer sends emails but it 100% was working at some point!
Maybe its an issue with the host or the server but I've no clue.
Here is the contact form php.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$emailFrom = 'myemail#gmail.com';
$emailSubject = 'New Form Submission';
$emailBody = "Name: $name. \n".
"Email: $email. \n".
"Phone: $phone 'n".
"Message: $message.";
$to = 'myemail#gmail.com';
$headers = "From: $emailFrom \r\n";
$headers .= "Reply to $email \r\n";
mail($to,$emailSubject,$emailBody,$headers);
header("Location: index.php")
?>
And here is the forms html
<div id="contact" class="container contact-form">
<div id="contactAnchor"></div><!--CONTACT ANCHOR TAG-->
<div class="contact-image">
<img id="contactLogo" src="/img/sam avatar no bg.png" width="150px" alt="SDB logo"/>
</div>
<form method="post" action="contactform.php">
<h3>Drop Me a Message</h3>
<div class="row">
<div class="col">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Your Name *"/>
</div>
<div class="form-group">
<input type="text" name="email" class="form-control" placeholder="Your Email *"/>
</div>
<div class="form-group">
<input type="text" name="phone" class="form-control" placeholder="Your Phone Number"/>
</div>
</div>
<div class="col">
<div class="form-group">
<textarea name="message" class="form-control" placeholder="Your Message *" style="width: 100%; height: 150px;"></textarea>
</div>
<div class="form-group">
<input type="submit" name="btnSubmit" class="btn btn-success" value="Send Message" />
</div>
</div>
</div>
</form>
</div>
Not sure if this solves it, but your reply to header is incorrect:
$headers .= "Reply-To: $email \r\n";

Print the value of datepicker and send it to my email

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>

Input radio not sending data

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.

Contact Form Not Working (PHP)

I have a contact form on a page that should send the details/message to an email address. You can view it here (it's in the footer): http://tedsrestaurant.com/index-working.html
HTML
<form id="contact-form" class="row style1" action="#" method="post">
<div class="col-xs-12 col-sm-4">
<div class="form-group">
<input name="name" type="text" id="name" placeholder="Your name" required />
</div>
<div class="form-group">
<input name="number" type="text" id="number" placeholder="Your number" required />
</div>
<div class="form-group">
<input name="email" type="email" id="email" placeholder="Your e-mail" required />
</div>
</div>
<div class="col-xs-12 col-sm-8">
<textarea name="message" rows="4" class="h130" id="message" placeholder="Write your message..." required></textarea>
</div>
<div class="clear"></div>
<div class="col-md-9"><p>* When booking the <strong>Food Truck</strong>, please write date, time and number of guests into your message.</p></div>
<div class="col-md-3 right">
<input class="submit btn" type="submit" value="Send a message" />
<input class="modal btn hidden" type="button" value="Send a message" name="" data-toggle="modal" data-target="#modalBox" />
</div>
<!-- Modal window -->
<div class="modal fade bs-modal-md" id="modalBox" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Contact form</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn right" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
And the PHP is:
<?php
//******** Email settings ********//
//your email
$email_to = "myemail#gmail.com";
//subject of email
$email_subject = "This is a message";
//message after success send mail
$email_send = "<div class='alert alert-success'>
<strong>Contact form was sent successfully.</strong>
<br/>Thank you for contacting us. We will be in touch with you very soon.</div>";
if($_POST) {
//******** Email data ********//
$cust_name = $_POST['name'];
$cust_number = $_POST['number'];
$cust_email = $_POST['email'];
$cust_message = $_POST['message'];
$header = "From:" . $cust_email . "\r\n";
$header .= 'MIME-Version: 1.0' ."\r\n";
$header .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$body = "<strong>Customer email:</strong> " . $cust_email . "<br/>";
$body .= "<strong>Customer number:</strong> " . $cust_number . "<br/>";
$body .= "<strong>Customer name:</strong> " . $cust_name . "<br/>";
$body .= "<strong>Message:</strong> " . $cust_message;
if($cust_name && $cust_number && $cust_email && mail($email_to, $email_subject, $body, $header)) {
echo $email_send;
echo '<script>$("#contact-form").each(function(){
this.reset();
});
</script>';
} else {
echo "<div class='alert alert-warning'><strong>Error sending mail. Please fill the contact form correctly or contact website administrator.</strong></div>";
}
}
Does everything look correct? FYI the PHP on the site has a real email address, not myemail#gmail.com. Once I hit the submit button I am taken to the same page, but nothing ever comes to my e-mail.
What is the output that you receive? An email_sent or error message?
If you get neither which I guess is the case, you should be using
if($_SERVER['REQUEST_METHOD'] == "POST") in place of if($_POST) to check if the request type is POST and further proceed.
I recommend to use SwiftMailer.
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);

Cannot POST /.php file when submitting form for email

I'm trying to get a HTML from to work together with PHP in order to make a form for sending a mail, but after submitting the form, PHP file is saying
Cannot POST /quotation.php
Here is my HTML code
<div id="quotation" class="reveal-modal" data-reveal>
<a class="close-reveal-modal">×</a>
<h3>Request Quotation</h3>
<p>Please fill out this information and we will contact you as soon as possilble.</p>
<form method="post" name="" action="quotation.php">
<div class="row">
<div class="large-6 columns">
<label>Name
<input type="text" name="name" placeholder="Name" />
</label>
</div>
<div class="large-6 columns">
<label>Lastname
<input type="text" name="lastname" placeholder="Lastname" />
</label>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<label>Company name
<input type="text" name="company" value="" placeholder="Your company">
</label>
</div>
<div class="large-6 columns">
<label>E-mail
<input type="text" name="email" value="" placeholder="E-mail">
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Additional details
<textarea name="message" placeholder="Additional details here"></textarea>
</label>
</div>
</div>
<input class="button radius" type="submit" name='submit' value="submit">
</form>
</div>
And this is the PHP that runs the form
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = $visitor_email;//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name, $lastname.\n".
"Here is the message:\n $message".
$to = "email#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
alert("yo");
//done. redirect to thank-you page.
header('Location: index.html');
?>
I added alert and echo for submit button, but none of them appears so looks like PHP is not even running.
It would be great if someone could guide me trough this problem or point out what am I doing wrong.

Categories