I´m tring to add a success message to my form after you click submit, but i dont know how, i have tried different code from different websites, but they dont work with my code. What line do i need to add to this code please?
<form action="contact.php" method="post" id="contact">
<h1>Contact-me!</h1>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="name">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="name#example.com">
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea name="message" class="form-control" id="message" rows="3"></textarea>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary mb-3" value="SEND MESSAGE">Submit</button>
<div>
</div>
</div>
</form>
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = '';
$email_subject = "New Form Submission";
$email_body = "User Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$to = "";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: index.html");
?>
Related
I cant seem to figure out what the problem is with my code. After pressing submit it will redirect to a error page and says "This page isn’t working website is currently unable to handle this request. HTTP ERROR 500"
HTML
<div class="container">
<form action="contact.php" method="POST" class="form">
<div class="form-group">
<label for="name" class="form-label">Your Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Jane Doe" tabindex="1" required>
</div>
<div class="form-group">
<label for="email" class="form-label">Your Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="jane#doe.com" tabindex="2" required>
</div>
<div class="form-group">
<label for="subject" class="form-label">Subject</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="Hello There!" tabindex="3" required>
</div>
<div class="form-group">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" rows="5" cols="50" id="message" name="message" placeholder="Enter Message..." tabindex="4"></textarea>
</div>
<div>
<button type="submit" class="btn">Send Message!</button>
</div>
</form>
</div>
PHP
<?php
$message_sent = false;
if(isset($_POST['email]') && $_POST['email'] != ''){
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ){
$userName = $_POST['name'];
$userEmail = $_POST['email'];
$messgeSubject = $_POST['subject'];
$message = $_POST['message'];
$to = "email"
$body = "";
$body .= "From: ".$userName. "\r\n";
$body .= "Email: ".$userEmail. "\r\n";
$body .= "Message: ".$message. "\r\n";
mail($to,$messgeSubject,$body);
$message_sent = true;
}
}
?>
there is an typing error in your php (line no 3).. you have written
isset($_POST['email]'
it should be
isset($_POST['email'])
My bootstrap 4 form is not sending any messages, I've uploaded the index.php and contact.php files on the server and I'm not having any response. Would you be able to help me find the problem?
Landing page with simple form
<form id="#contacts" method="POST" class="form" role="form">
<div class="row">
<div class="col-md-6 form-group">
<input class="form-control" id="name" name="name"
placeholder="Podaj swoje Imię i nazwisko" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="website" name="website"
placeholder="Adres strony www" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="telephone" name="telephone"
placeholder="Podaj swój numer telefonu" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="email" name="email"
placeholder="Podaj swój email" type="email" required/>
</div>
</div>
<textarea class="form-control" id="message" name="message" placeholder="Twoja wiadomość"
rows="4"></textarea>
<br>
<div class="row">
<div class="col-md-12 form-group">
<button class="btn btn-primary" type="submit">Wyślij</button>
</div>
</div>
</form>
contact.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$website = $_POST['website'];
$telephone = $_POST['telephone'];
$email_from = 'SEO';
$email_subject = 'Wiadomość kontaktowa z... '
$email_body = "Name: $name.\n".
"Email: $email.\n".
"Message: $message.\n";
"Website: $website.\n";
"Telephone: $telephone.\n";
$to = "biuro#of.pl";
$headers = "From: $email_from r\n";
$headers .= "Reply-To: $email r\n";
mail($to,$email-$email_subject,$email_body,$headers);
header("location: index.php");
?>
Your form is missing Action
<form id="#contacts" method="POST" class="form" role="form" action="contact.php">
I have created a simple Html page index.html where the user can submit a message. An additional PHP file email_form.php is created to capture the form submissions and send the form contents to my email address.
index.html:
<form name="contactform" method="POST" action="email_form.php">
<div class="form-group">
<div class="form-row">
<div class="col" id="prenom">
<input type="text" class="form-control" placeholder="Prénom" required="True" name="prenom">
</div>
<div class="col" id="nom">
<input type="text" class="form-control" placeholder="Nom" required="True" name="nom">
</div>
</div>
<div class="col" id="age">
<input type="number" class="form-control" placeholder="Age" required="True" name="age">
</div>
<div class="form-row">
<div class="col" id="tel">
<input type="tel" class="form-control" placeholder="Téléphone" name="tel">
</div>
<div class="col" id="mail">
<input type="email" class="form-control" placeholder="Email" name="email">
</div>
</div>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Your message" name="message"></textarea>
<div class="row">
<div class="col-xs-6" id="button">
<button type="submit" name="submit" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</form>
email_form.php:
<?php
if(isset($_POST['submit'])) {
$email_to = "info#mysite.com";
$email_subject = "Email subject";
$prenom = $_POST['prenom'];
$nom = $_POST['nom'];
$age = $_POST['age'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$message = $_POST['message'];
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Prénom: ".clean_string($prenom)."\n";
$email_message .= "Nom: ".clean_string($nom)."\n";
$email_message .= "Age: ".clean_string($age)."\n";
$email_message .= "Telephone: ".clean_string($tel)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = "From: ".$email."\n\n";
mail($email_to, $email_subject, $email_message, $headers);
header("Location: index.html");
}
?>
On the website, when I try to submit a message, it redirects me to a link looking like this: mysite.com/email_form.php with an error saying "page not found". I don't know much about PHP and I can't tell what I'm doing wrong.
First of all you should have a closing form tag </form>
Then:
Paste the php code to the top of your HTML file and
Change the file's extension to .php
Change the form's action to index.php
Your index.php should look something like this:
<?php
if(isset($_POST['submit'])) {
$email_to = "info#mysite.com";
$email_subject = "Email subject";
$prenom = $_POST['prenom'];
$nom = $_POST['nom'];
$age = $_POST['age'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$message = $_POST['message'];
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Prénom: ".clean_string($prenom)."\n";
$email_message .= "Nom: ".clean_string($nom)."\n";
$email_message .= "Age: ".clean_string($age)."\n";
$email_message .= "Telephone: ".clean_string($tel)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = "From: ".$email."\n\n";
mail($email_to, $email_subject, $email_message, $headers);
header("Location: index.html");
}
?>
<form name="contactform" method="POST" action="index.php">
<div class="form-group">
<div class="form-row">
<div class="col" id="prenom">
<input type="text" class="form-control" placeholder="Prénom" required="True" name="prenom">
</div>
<div class="col" id="nom">
<input type="text" class="form-control" placeholder="Nom" required="True" name="nom">
</div>
</div>
<div class="col" id="age">
<input type="number" class="form-control" placeholder="Age" required="True" name="age">
</div>
<div class="form-row">
<div class="col" id="tel">
<input type="tel" class="form-control" placeholder="Téléphone" name="tel">
</div>
<div class="col" id="mail">
<input type="email" class="form-control" placeholder="Email" name="email">
</div>
</div>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Your message" name="message"></textarea>
<div class="row">
<div class="col-xs-6" id="button">
<button type="submit" name="submit" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</form>
I have resolved the problem by changing headerin email_form.php. Now it looks like this:
header("Location: https://example.com");
And it works fine.
I have a created a html form and a php file (mail.php) and i have added this in my form <form action="mail.php" method="POST">
but When I try to submit the form, instead of emailing me and providing the thank you message, it downloads the php page. When I run the .html page in my browser, it shows up fine but when I click send it downloads mail.php, instead of working.
Any suggestions?
ok this is the code
mail.php:
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
$formcontent=" From: $name \n telephone: $telephone \n comments: $comments";
$recipient = "lllkk#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" ;
test.html:
<form action="mail.php" method="POST">
<div class="row">
<div class="form-group col-md-8 col-md-offset-1">
<input type="text" name="name" placeholder="Name" class="form-control">
</div>
<div class="form-group col-md-8 col-md-offset-1">
<input type="email" name="email" placeholder="Email" class="form-control">
</div>
<div class="form-group col-md-8 col-md-offset-1">
<input type="tel" name="telephone" placeholder="telephone" class="form-control">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-8 col-md-offset-1">
<textarea class="form-control" name="comments" placeholder="Comments" rows="6"></textarea>
</div>
</div>
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
Hi I'm trying develop a simple contact form in php. I have done a lot of research but can't seem to solve this.
Here is the HTML code:
<form id="contact-form" action="contact.php" method="post" class="clearfix">
<div class="contact-box-hide">
<div class="col-sm-6">
<input type="text" class="form-control" id="first_name" name="first_name" required placeholder="First Name">
<span class="first-name-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="last_name" name="last_name" required placeholder="Last Name">
<span class="last-name-error"></span>
</div>
<div class="col-sm-6">
<input type="email" class="form-control" id="contact_email" name="contact_email" required placeholder="Email Address">
<span class="contact-email-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="subject" name="contact_subject" required placeholder="Subject">
<span class="contact-subject-error"></span>
</div>
<div class="col-sm-10">
<textarea class="form-control" rows="5" id="message" name="message" required placeholder="Message"></textarea>
<span class="contact-message-error"></span>
</div>
<div class="col-sm-2">
<button id="contact-submit" class="btn custom-btn col-xs-12" type="submit" name="submit"><i class="fa fa-rocket"></i></button>
<span id="contact-loading" class="btn custom-btn col-xs-12"> <i class="fa fa-refresh fa-spin"></i> </span>
</div>
</div><!-- /.contact-box-hide -->
<div class="contact-message"></div>
</form><!-- /#contact-form -->
And this is the PHP portion:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$contact_email = $_POST['contact_email'];
$contact_subject = $_POST['contact_subject'];
$message = $_POST['message'];
$subject = "New Message from Website Form";
$submit = $_POST['submit'];
if($submit){
//Prepare Email
$from = 'From: My Website'."\r\n";
$to = 'odeleon#outlook.com';
$subject = "Message from United Passions for Christ.org";
$body = "".
"From: ".$first_name."\n".
"E-mail: ".$contact_email."\n".
"Message: ".$message."\n";
//Send email
if(mail($to, $subject, $body, $from)){
echo '<p>Your message has been sent!</p>';
}
}
?>
he contact form shows up OK and there aren't any php errors when the user hits submit. However the email never appears in my inbox. Any ideas?
Is there something that I'm missing from this?
Check php.ini file configuration, you can find that in /etc/ directory.
Refer this http://www.tutorialspoint.com/php/php_sending_emails.htm
Try
if(isset($_POST['submit'])){
//your code to submit
}