My objective is to call a "Thank you" modal message after successfully sending a quotation to an email, but I can't find the right code to do so. This is how the page works. I will fill up the form, then after I submit it, it will load the form.php, which has the code to send the email from the user to the assigned email which the message is supposed to be sent. After that, form.php will confirm if the email was successfully sent or not. My problem is, suppose that the message was sent, how will I redirect to the main index.html with the "Thank you" modal open?
Here's my index.html code.
<form class="login-form" method="post" action="php/form.php" name="quote-form" role="form">
<fieldset>
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Your Name" required data-error="Your Name is required.">
</div>
<div class="form-group">
<input type="text" name="phone_number" class="form-control" placeholder="Phone Number " required data-error="Phone Number is required.">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email Address" required data-error="Valid email is required.">
</div>
<! --Adding Radio button For Call Back -->
<div class="form-group">
<label>Request Phone Call?: <br>
<input type="radio" value ="Yes " required data-error="required." name="call">
<em>Yes</em><br>
<input type="radio" value ="No" required data-error="required." name="call">
<em>No</em><br>
</label>
</div>
<div class="form-group">
<textarea id="textinput" class="form-control" name="message" required rows="1" placeholder="Please provide the ff:
-Location
-Dimension (Total Area less openings, All side running meters for endcap computation)
-Color
-Profile (Cladding or Decking)
-If Pick up / Shipment / Delivery
-If with installation" maxlength="500"></textarea>
Remaining characters: <span id="count"></span>
</div>
<div class="form-group">
<label>
<input type="checkbox" required data-error="checkbox is required.">
<em>I agree with the <a data-dismiss="modal" aria-label="Close" data-toggle="modal" data-target=".bs-example-modal-md-5">(privacy policy)</a></em></label>
</div>
<button class="tg-theme-btn tg-theme-btn-lg" type="submit">Submit</button>
</fieldset>
</form>
Here's my full form.php code:
<?php
//Variable Declaraton
$name = $_POST['name'];
$email = $_POST['email'];
$to_email = "someone#example.com";
$subject = "New Quote";
$phoneNumber = $_POST['phone_number'];
$call = $_POST['call'];
$message = "From: $email\n" . "Client Sender: $name \n" . "Client Number: $phoneNumber\n" . "Call Back?: $call\n" . "\n\n" . "Message: \n\n" . $_POST['message'];
$headers = 'WPC Cladding & Decking Website <no-reply#aggtrading.com>';
//EMAIL CONFIRMATION
// --- Subject of confirmation email. ---------
$conf_subject = 'Your recent enquiry';
// Who should the confirmation email be from?
$conf_sender = 'AGGTE WPC Cladding & Decking <no-reply#aggtecomposites.com>';
$msg = "Your email: $email\n" . "Your Number: $phoneNumber\n" . "\n" ."Hi" ." ". $_POST['name'] . ",\n\nThank you for your recent enquiry. A member of our team will respond to your message as soon as possible.";
mail( $_POST['email'], $conf_subject, $msg, 'From: ' . $conf_sender );
//----------Send to company email. ---------
/* $send = #mail($to_email,$subject,$message,$headers); */
if(#mail($to_email,$subject,$message,$headers)) {
echo "<script> location.href='../index.html';
</script>";
}
else{
echo "<h1>Message not sent.</h1>";
}
?>
Here's the modal dialog that should open after redirecting from form.php after sending the email:
<!--my modal-->
<div id="myModal" class="modal fade bs-example-modal-md-2" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md-2" role="document">
<div class="modal-content">
<div class="top_links">Close (X)</div>
<h2 class="modal-title">GET A FREE QUOTE</h2>
<p>Thank you for sending us message! Feel free to explore more on our website!</p>
</div>
</div>
</div>
<!--my modal-->
Note: Here's the if/else that will redirect to index.html after confirming that the email was successfully sent:
if(#mail($to_email,$subject,$message,$headers)) {
echo "<script> location.href='../index.html'; </script>";
}
else{
echo "<h1>Message not sent.</h1>";
}
Thank you!
First set up a message variable instead of echo
Something like
$message = "IT WAS A SUCCESS";
Then initialize the Modal with the bootstrap jQuery initialization and place the Modal and the initialization itself ,under an if Statement.
if (isset($message)) {
Modal and initialization here
}
Set the message before the JavaScript redirect.
Related
I have a static site up (my portfolio site), with a form to send an email to me using a custom php.
the page is through github pages and the custom domain is through google.
the form is:
<div class="col-sm-12 col-md-6 wow fadeInUp" data-wow-duration="0.8s" data-wow-delay="0.2s">
<form id="contactForm" class="single-form quate-form wow fadeInUp" data-toggle="validator">
<div id="msgSubmit" class="h3 text-center hidden"></div>
<div class="row">
<div class="col-sm-12">
<input name="name" class="contact-name form-control" id="name" type="text" placeholder="First Name" required>
</div>
<div class="col-sm-12">
<input name="name" class="contact-email form-control" id="L_name" type="text" placeholder="Last Name" required>
</div>
<div class="col-sm-12">
<input name="name" class="contact-subject form-control" id="email" type="email" placeholder="Your Email" required>
</div>
<div class="col-sm-12">
<textarea class="contact-message" id="message" rows="6" placeholder="Your Message" required></textarea>
</div>
<!-- Subject Button -->
<div class="btn-form col-sm-12">
<button type="submit" class="btn btn-fill btn-block" id="form-submit">Send Message</button>
</div>
</div>
</form>
</div>
And the php to send it is:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$EmailTo = "#gmail.com";
$Subject = "Portfolio CV/Resume";
// prepare email body text
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success){
echo "success";
}else{
echo "invalid";
}
?>
The actual error I get is:
POST https://codewithmarcus.com/process.php 405 jquery.min.js:4
I removed my actual email address from the code but rest assured it is in there correctly, any help would be appreciated.
405 http code means Not Allowed response status code indicates that the request method is known by the server but is not supported by the target resource.
And you won't be able to send email via Gmail through this script. To send email through Gmail, you need send it through SMPT server. You can use PHPmailer libraryfor that.
I'm very new to PHP however, I have managed to get working an email system from a contact form on my front end of a webpage. The problem I have that once the email is sent, I wish to hide the form and display a message saying "thank you for the email."
I have tried to look for solutions, but the only answer I could find was to use this code: header("Location: sentmail.html"); From here then I redirect it to another HTML page, Identical to the contact page with the form removed. I feel this is bad practice as it will require many duping pages for how many contact forms are across the website.
Is there a way to display a "thank you for your message" Once the email has been sent rather then redirect to a sentmail.html page.
Thank you for taking the time to read.
`<?php
extract($_POST);
if(isset($_POST['submit']))
$name = $_POST['first_name'];
$email = $_POST['email_address'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "jamie#sharpsdigital.co.uk";
$headers = "From: MLS systems Contact Form ";
$txt = "$name has sent you an email from the address. " .$email. "\n\n With the message of.\n\n" .$message. " \n\n This is an automated response from the contact form, Please click on the blue email address above to respond." ;
mail ($mailTo, $subject, $txt, $headers);
header("Location: sentmail.html");
?>`
This is the PHP Code, and below the form code
<section class="free-appoinment-area">
<div class="container">
<form action="sendmail.php" method="post" class="free-appoinment-form">
<div class="row">
<div class="col-md-12">
<div class="sec-title text-left">
<h1>Any queries</h1><span class="decor"></span>
</div>
<div class="row">
<div class="col-md-12">
<div class="input-field">
<input name="first_name" placeholder="Your Name*" type="text">
<div class="icon-holder">
<span class="flaticon-people"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-field">
<input name="subject" placeholder="Your Subject" type="text">
<div class="icon-holder">
<span class="flaticon-people"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-field">
<input name="email_address" placeholder="Email Address*" type="text">
<div class="icon-holder">
<span class="flaticon-note"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-field">
<textarea name="message" placeholder="Your Message..."></textarea>
<div class="icon-holder comment">
<span class="flaticon-social-1"></span>
</div>
</div>
</div>
<div class="col-md-12">
<button type="submit" data-type="submit" name="submit" value="submit">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
you can do it with php and css.
the php way is by using if else statement, like bellow
if(isset($_POST['submit'])){
$name = $_POST['first_name'];
$email = $_POST['email_address'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "jamie#sharpsdigital.co.uk";
$headers = "From: MLS systems Contact Form ";
$txt = "$name has sent you an email from the address. " .$email. "\n\n With the message of.\n\n" .$message. " \n\n This is an automated response from the contact form, Please click on the blue email address above to respond." ;
if(mail ($mailTo, $subject, $txt, $headers)){
echo "Thanks for your contact.";
}
}else{ ?>
your form goes here
<?php }?>
There are hundreds of possibilities, but simply put, you can grab the return value of mail() and display contents according to this:
$success = mail('...');
form.php
if($success) {
echo 'Thank you!';
} else {
// output form here
}
Of course you can simply set a flag to true in your form handler too, but this is too broad to explain here.
I am by no means a developer. Self-taught, but can usually wing it enough to make things happen. Working on company website for boss, and having trouble with the form. Regardless of how I try to define the PHP variable, SOME are not sending the input value to the e-mail. I'm sure I'm missing something simple, thank you in advance for your help! This is what's not showing:
Website:
Average Monthly Volume:
Preferred Contact Method:
Here is what I have so far:
HTML FORM:
<div class="product-screens2">
<div style="padding:200px">
<div class="form">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage">Please retry.</div>
<form action="form-email" method="post" role="form" class="contactForm">
<div class="form-row">
<div class="form-group col-lg-6">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group col-lg-6">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Business Name" />
</div>
<div class="form-group col-lg-6">
<input type="text" name="name" class="form-control" id="business_site" placeholder="Business Website" />
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="name" id="avgvolume" placeholder="Average Monthly Volume" />
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="name" id="contactmethod" placeholder="Preferred Contact Method" />
</div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Brief Description of Goods or Services Sold"></textarea>
<div class="validation"></div>
</div>
<div class="text-center"><button type="submit" title="Send Message">SUBMIT</button></div>
</form>
</div></div>
</div>
PHP MAILER SCRIPT
<?php
/***************** Configuration *****************/
// Enter your email, where you want to receive the messages.
$contact_email_to = "Support#XXXXX.com";
// Subject prefix
$contact_subject_prefix = "Message From XXXXX Website: ";
// Name too short error text
$contact_error_name = "Name is too short or empty!";
// Email invalid error text
$contact_error_email = "Please enter a valid email!";
// Subject too short error text
$contact_error_subject = "Subject is too short or empty!";
// Message too short error text
$contact_error_message = "Too short message! Please enter something.";
/********** Do not edit from the below line ***********/
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die('Sorry Request must be Ajax POST');
}
if(isset($_POST)) {
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$subject = filter_var($_POST["subject"], FILTER_SANITIZE_STRING);
$message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
$business_site = $_POST["business_site"];
$avgvolume = $_POST["avgvolume"];
$contactmethod = $_POST["contactmethod"];
if(strlen($name)<4){
die($contact_error_name);
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
die($contact_error_email);
}
if(strlen($message)<3){
die($contact_error_subject);
}
if(strlen($message)<3){
die($contact_error_message);
}
if(!isset($contact_email_from)) {
$contact_email_from = "contactform#" . #preg_replace('/^www\./','', $_SERVER['SERVER_NAME']);
}
$sendemail = mail($contact_email_to, $contact_subject_prefix . $subject,
"Name: $name" . PHP_EOL .
"Reply-To: $email" . PHP_EOL .
"Business: $subject" . PHP_EOL .
"Website: $business_site" . PHP_EOL .
"Average Monthly Volume: $avgvolume" . PHP_EOL .
"Preferred Contact Method: $contactmethod" . PHP_EOL .
"Business Description: $message" . PHP_EOL .
"X-Mailer: PHP/" . phpversion()
);
if( $sendemail ) {
echo 'OK';
} else {
echo 'Could not send mail! Please check your PHP mail configuration.';
}
}
?>
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.
I am able to receive email with all the information except for the email address that is entered in the form, and when I receive the email, I get "No Sender" instead of the person's name. I am new to PHP and have done several Google searches but can't figure out what I am doing wrong. Please help. Thanks
This is my HTML:
<?php include("parts/doctype.php"); ?>
<?php include("parts/header.php"); ?>
<div class="page-wrap">
<?php include("parts/nav.php"); ?>
<div class="page-grid">
<h1 class="site-section-title">Contact Us</h1>
<div class="content-area">
<form action="send-mail.php" method="POST">
<div class="contactName">
<h1 class="heading Name">Name</h1>
<label for="first-name" class="first_name">First Name</label>
<input type="text" id="first_name" name="first_name" placeholder="Jane" autofocus required>
<label for="last_name" class="last_name">Last Name</label>
<input type="text" id="last_name" name="last_name" placeholder="Doe" required>
</div> <!-- end name -->
<div class="number">
<h1 class="heading">Phone Number</h1>
<label for="number" class="phone">Phone number</label>
<input type="tel" id="number" pattern="[0-9]{10}" name="sender_phone" placeholder="(###)-###-####">
</div> <!-- end number -->
<div class="email">
<h1 class="heading">Email Address</h1>
<label for="email" class="emailLabel">Email</label>
<input type="email" name="sender_email" placeholder="janedoe#gmail.com" required>
</div>
<div class="message">
<h1 class="heading">Message</h1>
<label for="message"></label>
<textarea name="sender_message" id="message" cols="30" rows="10" spellcheck="true" required> </textarea>
</div>
<button id="submit" class="send">Send</button>
</form>
</div> <!-- end content area -->
</div> <!-- end grid -->
</div> <!-- end page wrap -->
And this is my PHP:
<?php
$mail_to = 'removed address but I know it goes here'; // specify your email here
// Assigning data from the $_POST array to variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$mail_from = $_POST['sender_email'];
$phone = $_POST['sender_phone'];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'Its time for a cupcake Message from visitor ' . $first_name;
// Construct email body
$body_message = 'From: ' . $first_name . $last_name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Phone: ' . $phone . "\r\n";
$body_message .= 'Message: ' . $message;
// Construct email headers
$headers = 'From: ' . $first_name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){ ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. Should your message require a responce we will get back to you shortly.');
window.location = 'contactus.php';
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
alert('Message not sent. Please, try your message again. Should this still not work please contact use through facebook or twitter both links located on our home page.');
window.location = 'index.php';
</script>
<?php
}
?>
Your Label for should match your input id "First-Name" and "First_Name" won't match.
Here is a link:http://www.w3schools.com/tags/att_label_for.asp
Other than that it looks pretty good. If its not working as a post try using a get for your form method. That is easier to debug because the name value pairs will be passed on the url and you can at least verify that your php routine is sent the values correctly. If that looks good then try setting a break point in your php and stepping through it.
Hope this helps!