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">
Related
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");
?>
I've been having trouble with PHP (new to php) to clear my form fields AFTER a successful submission. I would also like to show an alert that it was successful. Any ideas? Using javascript with the onclick listener for the submit button will not work because it clears the fields before PHP has time to send the data.
Here is my html:
<div class="col-lg-7 mt-5 mt-lg-0 d-flex align-items-strech" data-aos="fade-left">
<form id="contact-form" action="contact-form-handler.php" method="post" role="form" class="php-email-form">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" data-rule="minlen:4" data-msg="Please enter at least 4 characters"/>
<div class="validate"></div>
</div>
<div class="form-group col-md-6">
<label for="name">Email</label>
<input type="email" name="email" class="form-control" id="email" data-rule="email" data-msg="Please enter at valid email"/>
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<label for="name">Subject</label>
<input type="text" class="form-control" name="subject" id="subject" data-rule="minlen:4" data-msg="Please enter a subject of at least 8 characters"/>
<div class="validate"></div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="10" data-rule="required" data-msg="Please enter a message"></textarea>
<div class="validate"></div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
Here is my PHP:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = "Portfolio Email";
$email_body = "Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$email_to = "email#gmail.com";
$headers = "From: $email_from \r\n";
mail($email_to, $subject, $email_body);
?>
If you do not want to use ajax, please try the following
(assuming the html is known as "form.html", and the php is "contact-form-handler.php")
The php redirection to form.html will clear the input fields (a normal behavior in web-browsers), and the javascript will show the word "successful" as an alert.
Please make further adjustment(s) according to your needs.
form.html
<div class="col-lg-7 mt-5 mt-lg-0 d-flex align-items-strech" data-aos="fade-left">
<form id="contact-form" action="contact-form-handler.php" method="post" role="form" class="php-email-form">
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" data-rule="minlen:4" data-msg="Please enter at least 4 characters"/>
<div class="validate"></div>
</div>
<div class="form-group col-md-6">
<label for="name">Email</label>
<input type="email" name="email" class="form-control" id="email" data-rule="email" data-msg="Please enter at valid email"/>
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<label for="name">Subject</label>
<input type="text" class="form-control" name="subject" id="subject" data-rule="minlen:4" data-msg="Please enter a subject of at least 8 characters"/>
<div class="validate"></div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="10" data-rule="required" data-msg="Please enter a message"></textarea>
<div class="validate"></div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
<script>
function get(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
</script>
<script>
if (get("result")=="success")
{
alert("Successful");
}
</script>
contact-form-handler.php
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = "Portfolio Email";
$email_body = "Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$email_to = "email#gmail.com";
$headers = "From: $email_from \r\n";
mail($email_to, $subject, $email_body);
?>
<script>
window.location.href="form.html?result=success"
</script>
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'])
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My php form has stopped sending through new enquiries to my email ever since I updated it to submit to self.
I've tried both an email address I use with my website host and a gmail address. Any suggestions will be much appreciated.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div class="col-lg-12">
<h2>Contact us!</h2>
<form class="form-horizontal" name="enquiryform" method="post" action="">
<div class="form-group-lg">
<label class="control-label col-xs-4" for="name">Name *</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="name" placeholder="First name" name="name" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="surname">Surname</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="surname" placeholder="Last name" name="surname">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="email">Email *</label>
<div class="col-xs-8">
<input type="email" class="form-control" id="email" placeholder="you#example.com" name="email" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="mobile">Mobile</label>
<div class="col-xs-8">
<input type="tel" class="form-control" id="mobile" placeholder="Phone number" name="mobile">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="message" name="message">Enquiry:</label>
<textarea class="form-control" id="message" rows="6" name="message" placeholder="Your message." required></textarea>
<div class="form-group">
<div class="col-xs-12">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</div>
</div>
</form>
</div>
</div>
<p></p>
<?php
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$message = $_POST['message'];
$formcontent="From: $email \n $name \n $surname \n $mobile \n Message: $message";
$recipient = "me#host.com";
$subject = "Enquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
</body>
The syntax of php email sending function is:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
mail($admin_email, "$first_name", $last_name, "$telephone", "$comments", "From:" . $email);
But in your case your parameter do not match with the required parameter.
Follow the syntax and try again.
You used extra parameters passed in your mail function.. I change some of your code look this.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
$action=$_REQUEST['action'];
if ($action=="")
{
?>
<div class="col-lg-12">
<h2>Contact us!</h2>
<form class="form-horizontal" name="enquiryform" method="post" action="">
<div class="form-group-lg">
<label class="control-label col-xs-4" for="first_name">Name *</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="name" placeholder="First name" name="name" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="surname">Surname</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="surname" placeholder="Last name" name="surname">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="inputEmail">Email *</label>
<div class="col-xs-8">
<input type="email" class="form-control" id="inputEmail" placeholder="you#example.com" name="email" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="telephone">Mobile</label>
<div class="col-xs-8">
<input type="tel" class="form-control" id="Mobile" placeholder="Phone number" name="mobile">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="exampleTextarea" name="message">Enquiry:</label>
<textarea class="form-control" id="exampleTextarea" rows="6" name="message" placeholder="Your message." required></textarea>
<div class="form-group">
<div class="col-xs-12">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</div>
</div>
</form>
</div>
</div>
<p></p>
<?php
}
else
{
$name = $_REQUEST['name'];
$surname = $_REQUEST['surname'];
$email = $_REQUEST['email'];
$mobile = $_REQUEST['mobile'];
$message = $_REQUEST['message'];
$formcontent="From: $email \n $name \n $surname \n $mobile \n Message: $message";
$recipient = "me#host.com";
$subject = "Enquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
}
?>
</body>
</html>
If any Query comment here...
This bootstrap using html/php contact form sends me an email just fine, but without any of the users input information!
The email I received looks empty like this:
Name:
Email:
Subject:
Message:
The html for the form is:
<section id="partner">
<div class="container">
<div class="center wow fadeInDown">
<h2><br>Contact</h2>
<p class="lead">Send a general enquiry here or order your service here.</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The PHP for the form looks like this:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'heerschapnikki#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Why isn't it working properly? The message "thank you for contacting us" pops up fine and the email sends through, but non of the users information comes through.
Try to print the values you are sending. So use this:
var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...
Doing this, you will be able to see wether your fields are even posted correctly.
the fields have no id param. in the post you get the "id" nor the "name"
<label>Name *</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" id="email" class="form-control" required="required">