PHP Message send page to same page pop up box - php

My website has a contact form using HTML and PHP. when the user presses the send button, it goes to a success page. How would I change this to turn into a pop up message on the same page as the contact form? Here is my code:
<section id="contact" class="main style3 blue">
<div class="content container">
<header>
<h2>Say Hello.</h2>
<p>You can use the form below to contact us regariding any form of inquiry</p>
</header>
<div class="box container 75%">
<!-- Contact Form -->
<form action="mail.php" method="POST">
<div class="row 50%">
<div class="6u 12u(mobile)"><input type="text" name="name" placeholder="Name" /></div>
<div class="6u 12u(mobile)"><input type="email" name="email" placeholder="Email" /></div>
</div>
<div class="row 50%">
<div class="12u"><textarea name="message" placeholder="Message (Please include your telephone number)" rows="6"></textarea></div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li><input type="submit" value="Send Message" /></li>
</ul>
</div>
</div>
</form>
</div>
</div>
</section>
The PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent = " From: $name \n Phone: $phone \n Message: $message \n Email: $email";
$recipient = "email#email.com";
$subject = "Message from the Site";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='/1/' style='text-decoration:none;color:#ff0099;'><strong> Return Home</strong></a>";
?>

Related

Contact Form submission failing?

I'm currently working on my portfolio. As of right now I'm trying to get the contact form to work. So I don't really know php that well and I'm not that good at it, but I've been googling and trying different ideas for myself. As of right now none of them have worked. Below I will attach the contact form html portion as well as the php I have now. Any help would be appreciated greatly
<section id="contact-form">
<!--Contact form section-->
<form method="POST" name="emailForm" action="index.php">
<!--Beginning of form and mail to my email address-->
<div class="contact-left">
<!--Contact info on the left side-->
<h1 class="c-l-heading">Contact</h1>
<!--Major heading-->
<div class="f-name">
<!--Name portion-->
<font>Name</font>
<input type="text" name="name" placeholder="Full Name" required/>
<!--Input field with a placeholder-->
</div>
<div class="f-email">
<!--email portion-->
<font >Email</font>
<input type="email" name="name" placeholder="Example#gmail.com" required/>
<!--Input field with a placeholder-->
</div>
</div>
<div class="contact-right">
<!--Contact info on the right side-->
<div class="message">
<!--Message portion-->
<font >Message</font>
<textarea name="message" rows="5" cols="20" placeholder="Write Message..." required></textarea>
<!--Textbox created-->
</div>
<button>submit</button>
<!--Submit button-->
</div>
</form>
</section>
PHP section now:
<?php
if(!isset($_POST['submit']))
{
echo "Error! You need to submit the form!";
}
//Collection
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validation
if(empty($name) || empty($visitor_email))
{
echo "Name and email are required"
exit;
}
$email_from = 'desmondlambkin17#gmail.com';
$email_subject = "dnjls.ca Contact Submission";
$email_body = "Name: $name\n"
"Email address: $visitor_email\n"
"Message: $message";
$to = "desmondlambkin17#gmail.com";
$headers = "From: $email_from";
//Send Email
mail($to, $email_subject, $email_body, $headers);
?>
Currently when I try to submit an email it says This page isn't working, and is currently unable to handle the request

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

How to redirect after an email has been sent

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.

Unable to get informations from a Html5 CSS and php form

I try to build a html5 form and send informations to form.php
<h3>Contact Me</h3>
<p></p>
<form method="post" action="form.php">
<div class="row uniform">
<div class="6u 12u(xsmall)">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u 12u(xsmall)">
<input type="email" name="email" id="email" placeholder="Email" />
</div>
</div>
<div class="row uniform">
<div class="12u">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row uniform">
<div class="12u">
<textarea name="message" id="message" placeholder="Message" rows="6"></textarea>
</div>
</div>
<div class="row uniform">
<div class="12u">
<ul class="actions">
<li>
<input type="submit" class="special" value="Send Message" />
</li>
<li>
<input type="reset" value="Reset Form" />
</li>
</ul>
</div>
</div>
</form>
At the same place I have form.php
<?
if (isset($_POST['name']) && isset($_POST['email'])) {
echo 'name '.$_POST['name'].' mail '.$_POST['email'];
}
?>
When I click on submit form.php page is open but blank.
<?php
if (isset($_POST['name']) && isset($_POST['email'])) {
echo 'name '.$_POST['name'].' mail '.$_POST['email'];
}
?>
I think you missed the opening of PHP tag its <?php and not <? .
Yes sorry, now I can send by mail.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: lespizz';
$to = 'jim#fdfrdsfg.com';
$subject = 'Hello';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
mail ($to, $subject, $body, $from)
?>
do you know how to get back on index.html automatically ?
Thanks
Using PHP you may redirect to another page with this code :
header("Location: index.html");
die();
But beware - it will work only if there was no output before!
Or if you have to give some output earlier you may just echo Javascript to redirect :
echo '<script type="text/javascript">
window.location = "http://www.google.com/"
</script>';

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