Problem in transmitting data from an HTML / PHP form - php

Good evening to all,
I did a project with Argon (Bootstrap / vue.js). This is a SPA with a contact section including a contact form (name, email, message). My contact form, is established on a .vue file, who is imported into my index.html:
<form class="needs-validation col-md-8 from-right" novalidate id="myForm" method="post" action="./index.php">
<div class="form-column">
<div>
<label for="nom">Saisissez votre nom</label>
<input type="text" class="form-control" id="nom" required placeholder="Votre nom" name="nom">
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre nom.
</div>
</div>
<div>
<label for="email" class="mt-3">Saisissez votre email</label>
<input type="email" class="form-control" id="email" placeholder="Votre email" name="email" required>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir un email valide.
</div>
</div>
<div>
<label for="message" class="mt-3">Saisissez votre message</label>
<textarea class="form-control" id="message" placeholder="Votre message ici" name="message" required></textarea>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre message.
</div>
</div>
</div>
<button class="btn btn-primary my-5 mx-auto" type="submit">Envoyer</button>
<div id="retourenvoimessage"></div>
</form>
I established an index.php file, supposed to retrieve the data from the HTML form, and forward it to me by email. I apologize in advance if my code offends PHP enthusiasts, for my part I do not know this language at all for the moment and have tried to get by by drawing on some documentation:
<?php
$nom = $_POST['nom'];
$email = $_POST['email'];
$message = $_POST['message'];
$dest = "fer.mathieu#gmail.com";
$sujet = "Demande de contact";
$corp = "Nom : $nom\n Email : $email\n Message : $message";
$headers = "From: $nom\n Reply-To: $email";
if (mail($dest, $sujet, $corp, $headers)) {
?><script>document.querySelector('#retourenvoimessage').textContent="Message bien envoyé, merci!"</script><?php
} else {
?><script>alert("Oups, un problème est survenu lors de l'envoi du message, désolé...");document.location.href="http://www.namesite.com/"</script><?php
}
?>
My wish was that during the submission, if successful, a message is added specifying the sending.
I have a javascript function which prevents the default behavior and therefore does not reload the page when submitting.
Yesterday I put my project online, and there "is the drama". When I fill in the fields of the form and submit it, firstly no message is added as wanted, but well that's not what bothers me the most.
I did receive an email from my host, containing the requested fields ('Name:', 'Email:', 'Message: "), but these are empty.
After much research on the net, not being able to find an answer to my problem, I motivate myself to post this one, at the risk of being hit with sticks if the problem, my mistake, was very simple Smiley confused.
Thank you in advance and sorry for my bad english.

The problem is probably caused by my Vue file. I do a new php file with PhpMailer, who works well in local mode. But when i submit my form, i no longer receive email as expected.
My Vue.js file:
<form class="needs-validation col-md-8 from-right" novalidate id="myForm" method="post" action="index.php">
<div class="form-column">
<div>
<label for="nom">Saisissez votre nom</label>
<input v-model="nom" type="text" class="form-control" id="nom" required placeholder="Votre nom" name="nom">
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre nom.
</div>
</div>
<div>
<label for="email" class="mt-3">Saisissez votre email</label>
<input v-model="email" type="email" class="form-control" id="email" placeholder="Votre email" name="email" required>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir un email valide.
</div>
</div>
<div>
<label for="message" class="mt-3">Saisissez votre message</label>
<textarea v-model="message" class="form-control" id="message" placeholder="Votre message ici" name="message" required></textarea>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre message.
</div>
</div>
</div>
<button class="btn btn-primary my-5 mx-auto" type="submit">Envoyer</button>
</form>
</div>
</section>
</template>
<script>
import BaseNav from "#/components/BaseNav";
import CloseButton from "#/components/CloseButton";
export default {
name: 'Contact',
data(){
return {
nom: '',
email: '',
message: ''
}
}
};
</script>
My PHP file:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'lib/PHPMailer/src/Exception.php';
require 'lib/PHPMailer/src/PHPMailer.php';
require 'lib/PHPMailer/src/SMTP.php';
$nom = $_POST['nom'];
$email = $_POST['email'];
$message = $_POST['message'];
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myadress#gmail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
//Recipients
$mail->setFrom($email, $nom);
$mail->addAddress('myadress#gmail.com');
// Content
$mail->isHTML(true);
$mail->Subject = 'Contact via portfolio';
$mail->Body = "Nom : $nom\n
Email : $email\n
Message : $message";
$mail->send();
echo 'Message bien envoyé';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
The Javascript function for the form:
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();

Related

verify if mail valid and phone

I have a problem. It's that when in the contact form we want to contact and we write an invalid email or a phone number there is the bootstrap alert which appears alert-success when I haven't even received the email
contact.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
if(isset($_POST["send"])){
$body = $_POST['message'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '73.auto.73#gmail.com';
$mail->Password = 'rlylecrtuvztqosz';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465;
$mail->setFrom('73.auto.73#gmail.com');
$mail->addAddress($_POST["email"]);
$mail->isHTML(true);
$mail->Subject = 'Projet web';
$mail->Body = "Message:" . $body . "<br>Phone number: " . $phone . "<br>Name: " . $name . "<br>Mail: " . $email;
$mail->send();
echo "success";
die;
}
index.php
<div class="col-md-4 mb-3 mb-md-0" data-aos="fade-left">
<form id="contactForm" action="contact.php" method="POST">
<input type="hidden" name="send">
<div class="alert alert-success" id="success-message" role="alert">
A simple success alert—check it out!
</div>
<div class="alert alert-danger" id="error-message" role="alert">
A simple success alert—check it out!
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1"><i class="bi bi-person-fill"></i></span>
<input type="text" id="name" name="name" class="form-control" placeholder="Nom Prénom"
aria-label="Nom Prénom" aria-describedby="basic-addon2" required>
</div>
<!-- Email address input -->
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">#</span>
<input type="text" id="email" name="email" class="form-control" placeholder="Email"
aria-label="email" aria-describedby="basic-addon1" required>
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1"><i class="bi bi-telephone-fill"></i></span>
<input type="text" id="phone" name="phone" class="form-control" placeholder="Téléphone"
aria-describedby="basic-addon2" required>
</div>
<!-- Message input -->
<div class="mb-3">
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"
placeholder="Decrivez le plus possible votre projet" name="message" required></textarea>
</div>
<!-- Form submit button -->
<div class="d-grid">
<button class="btn btn-primary btn-lg" name="send" type="submit" id="send-form">Submit</button>
</div>
</form>
</div>
<script>
AOS.init();
$(document).ready(function(){
$('#contactForm').submit(function(e){
e.preventDefault();
const $this = $(this);
// disable submit button
const $button = $(this).find('button[type="submit"]').text('Submit...').attr('disabled', 'disabled');
// send message
$.ajax({
type: 'POST',
url: 'contact.php',
data: $this.serialize(),
success: function(data){
$('#success-message').css('display', 'block');
$this[0].reset(); // reset form
},
error: function(jqXHR, textStatus, errorThrown){
$('#error-message').css('display', 'block');
},
complete: function(jqXHR, textStatus){
// enable submit button
$button.text('Submit').removeAttr('disabled');
}
})
})
})
</script>
Above you can see the code there is jquery ajax, php. I would like to know how I can do so that it verifies the email if it is a written email (that is to say in this format: mymail#mail.com
I receive the email when I am contacted and if the email is not valid (#mail.com) there is the bootstrap alert which appears write email not sent because the email is invalid I would like to do this for the email and the phone so that only numbers can be entered. how can i do that?
First of all always use type="email" for email,
Second thing is never validate at client site only,
You have to validate on both end i.e: HTML and PHP, On PHP end validate this as:
$email_val = $_POST['email'];
if(filter($email_val, FILTER_VALIDATE_EMAIL)){
// enter code here
}
And same you can validate for phone number by applying regex.
if ($mail->send()) {
echo "success";
} else {
echo "unnable to sent mail id error!!!";
}

What is wrong with my php mail contact form?

I'm using a template for a contact form for my website. The problem is, when I test it on my server I cannot send a message. It will only give me my error message and not send. Did something happen when I translated the original send text to German?
I've tried debugging the vars. I've also tried to echo some string inputs.
This is the html code:
<form id="contact-form" action="mail.php" method="post">
<div class="row">
<div class="col-md-6 form-group">
<label class="sr-only">Name</label>
<input type="text" class="form-control input-lg" name="name" placeholder="Name" >
<p class="help-block text-danger"></p>
</div>
<div class="col-md-6 form-group">
<label class="sr-only">Email</label>
<input type="email" class="form-control input-lg" name="email" placeholder="Email" >
<p class="help-block text-danger"></p>
</div>
<div class="col-md-12 form-group">
<label class="sr-only">Betreff</label>
<input type="text" class="form-control input-lg" name="subject" placeholder="Betreff" >
<p class="help-block text-danger"></p>
</div>
<div class="col-md-12 form-group">
<textarea class="form-control input-lg" rows="7" name="message" placeholder="Nachricht"></textarea>
<p class="help-block text-danger"></p>
</div>
<div class="col-md-12 text-center">
<button type="submit" class="btn btn-lg btn-round btn-dark">Senden</button>
</div>
</div>
</form>
PHP:
<?php
// POST GET.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Form Felder GET.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$subject = trim($_POST["betreff"]);
$message = trim($_POST["nachricht"]);
// Check ob Daten an den mailer.
if ( empty($name) OR empty($subject) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// 400 (bad request) und raus.
http_response_code(400);
echo "Bitte füllen Sie alle Felder aus.";
exit;
}
// Empfaenger.
$recipient = "info#test.de";
// Betreff.
$subject = "Neue Anfrage von $name";
// Inhalt.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Betreff: $subject\n\n";
$email_content .= "Nachricht:\n$message\n";
// Header.
$email_headers = "Von: $name <$email>";
// Senden.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// 200 (okay).
http_response_code(200);
echo "Vielen Dank! Deine Nachricht wurde versendet.";
} else {
// 500 (internal server error).
http_response_code(500);
echo "Oops! Hier ist ein Fehler passiert, deine Nachricht konnte nicht gesendet werden.";
}
} else {
// 403 (forbidden).
http_response_code(403);
echo "Es gibt Probleme mit deiner Anfrage, bitte versuche es ernuet.";
}
?>
Your input name for subject is in English in your form, but in your php file is in German
Choosing the same lang for all your code can to avoid confussions
Change name attributes to german to make it work
<input type="text" class="form-control input-lg" name="betreff" placeholder="Betreff" >
<textarea class="form-control input-lg" rows="7" name="nachricht" placeholder="Nachricht">
</textarea>

Authenticated SMTP PHP code

I'm new in coding in PHP and I've been trying to figure out how to send contact form data through a SMTP authenticated PHP script. So far, it's been very frustating and I couldn't do it.
I have this bootstrap form on an HTML page and I don't know how to create the contact.php script to send it with SMTP authenticated.
<form id="contact-form" method="post" action="contato.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="form-group">
<label for="form_name">Nome:</label>
<input id="form_name" type="text" name="name" class="form-control" placeholder="Qual o seu nome?" required="required" data-error="Você precisa informar seu nome.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="form_email">Email:</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Qual o seu e-mail?" required="required" data-error="Insira um e-mail válido.">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="form_phone">Fone:</label>
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Qual o seu telefone?">
<div class="help-block with-errors"></div>
</div>
`enter code here`</div>
<div class="row">
<div class="form-group">
<label for="form_message">Mensagem:</label>
<textarea id="form_message" name="message" class="form-control" placeholder="Mensagem para o Rancho" rows="4" required="required" data-error="Qual a sua mensagem?"></textarea>
<div class="help-block with-errors"></div>
</div>
<input type="submit" class="btn btn-success btn-send" value="Enviar">
</div>
</div>
</form>
My contato.php
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.ranchopremier.com.br";
$mail->SMTPAuth = true;
$mail->Username = 'contato#ranchopremier.com.br';
$mail->Password = 'mypass';
$mail->SMTPSecure = 'tls';
$mail->From = "contato#ranchopremier.com.br";
$mail->Sender = "contato#ranchopremier.com.br";
$mail->FromName = "Locaweb";
$mail->AddAddress('contato#ranchopremier.com.br', 'Teste Locaweb');
$mail->AddAddress('id#live.com');
$mail->IsHTML(true);
$mail->Subject = "CONTATO DO SITE";
$mail->Body = 'Este é o corpo da mensagem de teste, em HTML!;
$mail->AltBody = 'Este é o corpo da mensagem de teste, em Texto Plano! \r\n;
$enviado = $mail->Send();
$mail->ClearAllRecipients();
$mail->ClearAttachments();
if ($enviado) {
echo "E-mail enviado com sucesso!";
} else {
echo "Não foi possível enviar o e-mail.";
echo "Informações do erro:" . $mail->ErrorInfo;
}
?>
If anyone would like to help I will appreciate.
Thanks

Contact form not working with Bootstrap+PHP

I'm trying to send an email via HTML5 with bootstrap + php.
HTML:
<form name="frmContacto" class="form-horizontal" method="post" action="mail/contact_me.php">
<fieldset>
<legend class="text-center header">Formulario de contacto</legend>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-user bigicon"></i></span>
<div class="col-md-8">
<input id="fname" name="name" type="text" placeholder="Nombre" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-user bigicon"></i></span>
<div class="col-md-8">
<input id="lname" name="name" type="text" placeholder="Apellidos" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
<div class="col-md-8">
<input id="email" name="email" type="text" placeholder="Correo electrónico" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-phone-square bigicon"></i></span>
<div class="col-md-8">
<input id="phone" name="phone" type="text" placeholder="Teléfono" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-pencil-square-o bigicon"></i></span>
<div class="col-md-8">
<textarea class="form-control" id="message" name="message" placeholder="Introduce aquí tu mensaje." rows="7"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<a href="mailto:xxx#example.com?Subject=Hello%20again" target="_top">
<button type="submit" class="btn btn-primary btn-lg">Enviar</button>
</a>
</div>
</div>
</fieldset>
</form>
PHP:
<?php
// Check for empty fields
if (empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)
) {
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'xxx#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Formulario de contacto web: $name";
$email_body = "Ha recibido un nuevo mensaje desde la web.\n\n" . "Detalles:\n\Nombre: $name\n\nEmail: $email_address\n\Teléfono: $phone\n\Mensaje:\n$message";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to, $email_subject, $email_body, $headers);
return true;
?>
I don't know if I have to import something in the HTML. It seems that the php mail() function is not being called, since I have a breakpoint in the function line and nothing happens when I click the "Submit" button. Also, the email is the same in $to php function and in the HTML "mailto".
Thanks a lot.
Check the following things-
1. In your HTML you have declared Name Line of form twice, which is not required.
2. You should have setting in your server/PHP configuration file configured to a mail Server. Without Mail server connected, you can't send mails
Have you validate your settings in php.ini (sendmail parameter) ?
You might read this if needed:
https://blog.codinghorror.com/so-youd-like-to-send-some-email-through-code/
The Code is below is well commented so there is no point writing much. Just read through the Comments. It is quite self-explanatory:
PHP
<?php
// GET ALL POSTED FIELD-VALUES AND ASSIGN THEM DEFAULT VALUES OF NULL (IF THEY ARE NOT YET SET...
$lastName = isset($_POST['last_name']) ? htmlspecialchars(trim($_POST['last_name'])) : null;
$firstName = isset($_POST['first_name']) ? htmlspecialchars(trim($_POST['first_name'])) : null;
$email = isset($_POST['email']) ? htmlspecialchars(trim($_POST['email'])) : null;
$phone = isset($_POST['phone']) ? htmlspecialchars(trim($_POST['phone'])) : null;
$message = isset($_POST['message']) ? htmlspecialchars(trim($_POST['message'])) : null;
// VALIDATE THE FIELDS: BUT FIRST CREATE AN ARRAY
// TO HOLD ERROR MESSAGES FOR FIELDS THAT FAILED THE VALIDATION.
$arrErrorBag = array();
$strErrorMessage = "";
// VALIDATE E-MAIL:
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$arrErrorBag["E-Mail"] = "The Email you entered in not valid.";
}
// VALIDATE FIRST NAME:
if(!preg_match('#(^[a-zA-z])?([\w\.\-\ ])*\w*$#i', $firstName)){
$arrErrorBag["First Name"] = "First Name Should not be Empty and should contain only alpha-numeric Characters.";
}
// VALIDATE LAST NAME:
if(!preg_match('#(^[a-zA-z])?([\w\.\-\ ])*\w*$#i', $lastName)){
$arrErrorBag["Last Name"] = "Last Name Should not be Empty and should contain only alpha-numeric Characters.";
}
// VALIDATE PHONE:
if(!preg_match('#^(\+\d{1,3})?\s?(\d{2,4})\s?(\d{2,4})\s?(\d{2,4})\s?(\d{2,4})$#', $phone)){
$arrErrorBag["Phone"] = "Telephone Number should be Numeric and Should not be Empty.";
}
// VALIDATE MESSAGE:
if(!preg_match('#([\w\.\-\d\ ])*\w*$#si', $name)){
$arrErrorBag["Message"] = "Message Should not be Empty and should contain only alpha-numeric Characters only.";
}
if(!empty($arrErrorBag)){
// WE HAVE SOME ERRORS SO WE BUILD A STRING MESSAGE BASED ON THE ERRORS WE HAVE GATHERED ABOVE...
$strErrorMessage .= "<h6 class='error-heading'>There are Errors in the Form Please, correct them to continue.</h6>";
foreach($arrErrorBag as $fieldName=>$errorMessage){
$strErrorMessage .= "<div class='error-block'><strong>{$fieldName}: </strong>";
$strErrorMessage .= "<span>{$errorMessage}: </span></div>";
}
}else{
// THE FORM IS CLEAN AND VALID SO WE SEND THE E-MAIL:
$name = $firstName . " " . $lastName;
$to = 'xxx#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Formulario de contacto web: $name";
$email_body = "Ha recibido un nuevo mensaje desde la web.\n\n" . "Detalles:\n\Nombre: {$name}\n\nEmail: {$email}\n\Teléfono: {$phone}\n\Mensaje:\n{$message}";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: {$email}";
mail($to, $email_subject, $email_body, $headers);
// THE MAIL WAS SENT SO YOU CAN NOW REDIRECT TO ANOTHER PAGE... MAYBE A THANK YOU PAGE...
$redirectURL = "thank-you.php"; //<== THIS IS ONLY AN EXAMPLE... THE URL SHOULD RATHER BE ANY PAGE OF YOUR CHOOSING.
header("location: " . $redirectURL);
}
?>
HTML
<!-- BEFORE THE FORM, CREATE A DIV TO HOLD ERROR MESSAGE, IN CASE ERRORS OCCUR... -->
<!-- IN THIS SCENARIO, IT IS IDEAL TO HAVE BOTH THE PHP AND THE HTML INSIDE THE SAME FILE... -->
<!-- THE PHP CODE SHOLD BE AT THE TOP OF THE FILE & THE HTML MARKUP BELOW... -->
<!-- NOTICE THAT THE ACTION ATTRIBUTE OF THE FORM IS NOW EMPTY... THIS FORCES THE FORM TO SUBMIT BACK TO ITSELF: THIS PAGE... -->
<div class="error-msg-wrapper"><?php echo $strErrorMessage; ?></div>
<form name="frmContacto" class="form-horizontal" method="post" action="">
<fieldset>
<legend class="text-center header">Formulario de contacto</legend>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center">
<i class="fa fa-user bigicon"></i>
</span>
<div class="col-md-8">
<input id="fname" name="first_name" type="text" placeholder="Nombre" value="<?php echo $firstName; ?>" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center">
<i class="fa fa-user bigicon"></i>
</span>
<div class="col-md-8">
<input id="lname" name="last_name" type="text" placeholder="Apellidos" value="<?php echo $lastName; ?>" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center">
<i class="fa fa-envelope-o bigicon"></i>
</span>
<div class="col-md-8">
<input id="email" name="email" type="text" placeholder="Correo electrónico" value="<?php echo $email; ?>" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center">
<i class="fa fa-phone-square bigicon"></i>
</span>
<div class="col-md-8">
<input id="phone" name="phone" type="text" placeholder="Teléfono" value="<?php echo $phone; ?>" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center">
<i class="fa fa-pencil-square-o bigicon"></i>
</span>
<div class="col-md-8">
<textarea class="form-control" id="message" name="message" placeholder="Introduce aquí tu mensaje." rows="7"><?php echo $message; ?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<input type="submit" class="btn btn-primary btn-lg" value="Enviar" />
</div>
</div>
</fieldset>
</form>

PHP in bootstrap form not working

I have been trying to add php to a bootstrap form via the following tutorial: https://bootstrapbay.com/blog/working-bootstrap-contact-form/. But nothing happens when I click the submit button - I just go back/stay to the same page with an empty form. I don't receive an email nor any error actions when I don't fill out some fields either. Below my code. The name of the document is werkwijze.php. Does someone have an idea what I'm doing wrong? Thanks a lot in advance!
<?php
if (isset($_POST['submit'])){
$voornaam = $_POST['voornaam'];
$familienaam = $_POST['familienaam'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$vraag = $_POST['vraag'];
$from = 'info#tbep.be';
$to = 'eefje.vanhemelryck#gmail.com';
$subject = 'Vraag van op uw website www.tbep.be';
$body = "From: $voornaam $familienaam\n E-Mail: $email\n Telefoon: $tel\n Vraag: $vraag";
// Check if name has been entered
if (!$_POST['voornaam']) {
$errVoornaam = 'Gelieve uw voornaam op te geven';
}
if (!$_POST['familienaam']) {
$errFamilienaam = 'Gelieve uw familienaam op te geven';
}
// Check if email en phone has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Gelieve uw emailadres op te geven';
}
if (!$_POST['tel']) {
$errTel = 'Gelieve uw telefoonnummer op te geven';
}
//Check if message has been entered
if (!$_POST['vraag']) {
$errVraag = 'Gelieve uw vraag te stellen';
}
// If there are no errors, send the email
if (!$errVoornaam && !$errFamilienaam && !$errEmail && !$errTel && !$errVraag) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Hartelijk dank. Ik neem zo snel mogelijk contact met u op!</div>';
} else {
$result='<div class="alert alert-danger">Sorry, er was een probleem met het versturen van dit formulier. Alternatief kan u ons een email sturen op info#tbep.be</div>';
}
}
}
?>
<form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="text/plain">
<div class="form-group">
<label class="control-label col-sm-3" for="voornaam">Voornaam:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="voornaam" name="voornaam" placeholder="Voornaam">
<?php echo "<p class='text-danger'>$errVoornaam</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="familienaam">Familienaam:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="familienaam" name="familienaam" placeholder="Familienaam">
<?php echo "<p class='text-danger'>$errFamilienaam</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Email:</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="telefoon">Telefoonnummer:</label>
<div class="col-sm-9">
<input type="tel" class="form-control" id="tel" name="tel" placeholder="Telefoonnummer">
<?php echo "<p class='text-danger'>$errTel</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="vraag">Uw vraag:</label>
<div class="col-sm-9">
<textarea class="form-control" rows="5" id="vraag" name="vraag" placeholder="Uw vraag"></textarea>
<?php echo "<p class='text-danger'>$errVraag</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" id="submit" name="submit" value="Send" class="btn btn-default">Versturen</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<?php echo $result; ?>
</div>
</div>
</form>
Please Remove enctype="text/plain" from your form.
<form class="form-horizontal" role="form" action="werkwijze.php" method="post">
Or use
<form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="multipart/form-data">

Categories