I have a form with different inputs. On submit i use Ajax to send the data to a MySQL table. If the inputs are blank the jQuery validate plugin stops the submit action.
The POST submit works because i use Firebug and the response Ajax tells me that; but the data doesn't save in my database.
I don't know which part is causing the problem because in JS it doesn't tell me any issue.
My HTML/JS code looks like this:
$(document).ready(function() {
$("#ok").hide();
$("#formula").validate({
rules: {
nombre: {required: true},
mail: {required: true},
estado: {required: true},
imagen: {required:true,
extension:'jpeg|png|jpg|gif'},
checa:{required:true}
},
messages: {
nombre: "Debe introducir su nombre.",
mail:"Introduce una dirección de e-mail válido.",
estado : "Debes seleccionar tu estado donde resides.",
imagen : "Selecciona una imagen válida, jpg, jpeg, png o gif.",
checa: "Debes aceptar los terminos de uso y la política de privacidad"
},
submitHandler: function(form){
var dataString = 'nombre='+ nombre
+ 'mail=' + mail
+ '&estado=' + estado
+ '&imagen=' + imagen
+ '&checa=' + checa
$("#ok").show();
$.ajax({
type: "POST",
url:"envia.php",
data: dataString,
success: function(msg){
$("#ok").html("<strong>Mensaje enviado existosamente, nos pondremos en contacto a la brevedad.</strong>");
document.getElementById("nombre").value="";
document.getElementById("mail").value="";
document.getElementById("estado").value="";
document.getElementById("imagen").value="";
document.getElementById("checa").value="";
setTimeout(function() {$('#ok').fadeOut('fast');}, 3000);
}
});
}
});
});
<section class="wrapper">
<form method="post" name="formulario" id="formula" enctype="multipart/form-data">
<div id="ok"></div>
<label>Nombre:</label>
<input type="text" name="nombre" id="nombre" />
<label>Email:</label>
<input type="email" name="mail" id="mail" />
<label>Estado:</label>
<!--<div class="styled-select">-->
<select name="estado" id="estado">
<option value="">Selecciona tu estado:</option>
<option>Aguascalientes</option>
<option>Baja California</option>
<option>Baja California Sur</option>
<option>Campeche</option>
<option>Chiapas</option>
<option>Chihuahua</option>
<option>Coahuila</option>
<option>Colima</option>
<option>Distrito Federal</option>
<option>Durango</option>
<option>Guanajuato</option>
<option>Guerrero</option>
<option>Hidalgo</option>
<option>Jalisco</option>
<option>México</option>
<option>Michoacán</option>
<option>Morelos</option>
<option>Nayarit</option>
<option>Nuevo León</option>
<option>Oaxaca</option>
<option>Puebla</option>
<option>Querétaro</option>
<option>Quintana Roo</option>
<option>San Luis Potosí</option>
<option>Sinaloa</option>
<option>Sonora</option>
<option>Tabasco</option>
<option>Tamaulipas</option>
<option>Tlaxcala</option>
<option>Veracruz</option>
<option>Yucatán</option>
<option>Zacatecas</option>
</select>
<!--</div>
<div id="file">Chose file</div>-->
<input type="file" name="imagen" id="imagen" class="upload" />
<input type="checkbox" name="checa" id="checa" value="Acepto">Acepto los terminos y condiciones y la politica de privacidad
<input name="URLBack" type="hidden" id="URLBack" value="<?php echo "hhtp://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" />
<input name="input" id="enviar" type="submit" value="Enviar" />
</form>
</section>
And my PHP file looks like this:
include 'conexion.php';
$con = conexion();
$nombre=substr($_POST['nombre'],0,2);
$sql= "SELECT MAX(id) FROM base_de_datos";
$rs=mysql_query($sql);
if(isset($rs) && mysql_num_rows($rs)>0)
{
$row=mysql_fetch_row($rs);
$num=$row;
mysql_free_result($rs);
}
$tumb = implode($num);
$sumando = $tumb + 1;
if ($_FILES["imagen"]["error"] > 0){
echo "ha ocurrido un error";
} else {
$permitidos = array("image/jpg", "image/jpeg", "image/gif", "image/png");
$limite_kb = 2000;
if (in_array($_FILES['imagen']['type'], $permitidos) && $_FILES['imagen']['size'] <= $limite_kb * 2048){
$ruta = "imagenes/" . $_FILES['imagen']['name'];
if (file_exists($ruta)){
echo $_FILES['imagen']['name'] . ", este archivo existe";
}
else{
$temp = explode(".", $_FILES["imagen"]["name"]);
$newfilename = 'contest'. $sumando . '.' . end($temp);
move_uploaded_file($_FILES["imagen"]["tmp_name"], "imagenes/" . $newfilename);
}
}
}
$caracteres = "AABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$numerodeletras=10;
$cadena = "";
for($i=0;$i<$numerodeletras;$i++)
{
$cadena .= substr($caracteres,rand(0,strlen($caracteres)),1);
}
$serie=$nombre.$sumando;
$este= date("Y/m/d");
echo $serie;
$_GRABAR_SQL = "INSERT INTO base_de_datos (nombre,email,estado,imagen,condiciones_de_uso,clave,fecha) VALUES ('$_POST[nombre]','$_POST[mail]','$_POST[estado]','$newfilename','$_POST[checa]','$serie','$este')";
mysql_query($_GRABAR_SQL);
$query=mysql_insert_id();
$headers = "MIME-Version: 1.0\r \n";
$headers .= "Content-type: text/html; charset=utf-8 \r \n";
$headers .= "Return-Path: ".$_POST['nombre']." <".$_POST['mail']."> \r \n";
$headers .= "From: OMA Plaza <noreply#example.com> \r \n";
$headers .= "Reply-To: ".$_POST['nombre']." <".$_POST['nombre']."> \r \n";
$headers .= "X-Priority: 1\r\n";
$mail = mysql_real_escape_string($_POST['mail']);
if ( function_exists( 'mail' ) )
{
echo 'mail() is available';
}
else
{
echo 'mail() has been disabled';
}
$asunto = "";
$confir = "Su mensaje fue enviado exitosamente, nos pondremos en contacto con usted a la brevedad";
$mensage = "---------------------------------- \n";
$mensage.= " Contacto \n";
$mensage.= "---------------------------------- \n";
$mensage.= "Nombre: ".$_POST['nombre']."\n";
$mensage.= "Clave Confirmación: ".$serie."\n";
$mensage.= "Email: ".$_POST['mail']."\n";
mail ($mail, $asunto, $mensage, $headers);
Related
i'm trying to add IconCaptcha (https://github.com/fabianwennink/IconCaptcha-Plugin-jQuery-PHP#installation) to a contact form.
I managed to implement it with success on the web page. But whenever i hit the SUBMIT button (with the other fields well filled) the form is sent. Even if i hit the wrong captcha... Or no captcha at all.
Here is the contact.php page code :
<?php
session_start();
require('IconCaptcha-PHP/src/captcha-session.class.php');
require('IconCaptcha-PHP/src/captcha.class.php');
IconCaptcha::setIconsFolderPath('../assets/icons/');
IconCaptcha::setIconNoiseEnabled(true);
if(!empty($_POST)) {
if(IconCaptcha::validateSubmission($_POST)) {
$captchaMessage = 'Le message a bien été envoyé!';
} else {
$captchaMessage = json_decode(IconCaptcha::getErrorMessage())->error;
}
}
?>
<!doctype html>
<!--
* IconCaptcha Plugin: v2.5.0
* Copyright © 2017, Fabian Wennink (https://www.fabianwennink.nl)
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
-->
<html>
<head>
<!--FORMAT-->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!--STYLES-->
<link href="css/styles.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap-4.3.1.css" rel="stylesheet" type="text/css">
<!-- IconCaptcha stylesheet -->
<link href="IconCaptcha-PHP/assets/css/icon-captcha.min.css" rel="stylesheet" type="text/css">
<script src="http://use.edgefonts.net/montserrat:n4:default.js" type="text/javascript"></script>
<!--SCRIPTS BOOTSTRAP-->
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap-4.3.1.js"></script>
<body>
<section id="contact" class="section-orange">
<div class="container-fluid" justify-content="center" style="width: 90%">
<!-- DEBUT FORMULAIRE CONTACT -->
<?php
if(isset($captchaMessage)) {
echo '<b>Captcha Message: </b>' . $captchaMessage;
}
?>
<form id="reused_form" role="form" method="post" action="envoiformulaire.php">
<div class="row">
<div class="col-md-6 form-group">
<label for="first_name"></label>
<input id="firstname" name="first_name" type="text" class="form-control" placeholder="Prénom" required="required">
</div>
<div class="col-md-6 form-group">
<label for="last_name"></label>
<input id="lastname" name="last_name" type="text" class="form-control" placeholder="NOM" required="required">
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label for="email"></label>
<input id="email" name="email" type="email" class="form-control" placeholder="Courriel" required="required">
</div>
<div class="col-md-6 form-group">
<label for="telephone"></label>
<input id="telephone" type="tel" name="telephone" onkeyup="formatte(this,2)" onkeypress="return isNumberKey(event)" class="form-control" placeholder="Téléphone" required="required" minlength="14" maxlength="14">
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="comments"></label>
<textarea id="message" name="comments" class="form-control" placeholder="Message (400 caractères maximum)" maxlength="400" rosws="4" required="required"></textarea>
</div>
<div class="col-md-12 form-group">
<div class="captcha-holder"></div>
</div>
<div class="col-md-12 form-group">
<br> <input type="submit" id="btnContactUs" class="btn btn-success btn-send" value="Envoyer le message">
</div>
</div>
</form>
<script src="IconCaptcha-PHP/assets/js/icon-captcha.min.js" type="text/javascript"></script>
<!-- Initialize the IconCaptcha -->
<script async type="text/javascript">
$(window).ready(function() {
$('.captcha-holder').iconCaptcha({
theme: ['light'],
fontFamily: '',
clickDelay: 500,
invalidResetDelay: 3000,
requestIconsDelay: 1500,
loadingAnimationDelay: 1500, // How long the fake loading animation should play.
hoverDetection: true,
showCredits: 'show',
enableLoadingAnimation: false,
validationPath: 'IconCaptcha-PHP/src/captcha-request.php',
messages: {
header: "Vous devez choisir, « …but, choose wiesly! »",
correct: {
top: "« You have chosen… wisely. »",
bottom: "Félicitations! Vous n'êtes pas un robot."
},
incorrect: {
top: "« You chose poorly! »",
bottom: "Oups! Mauvaise image."
}
}
})
.bind('init.iconCaptcha', function(e, id) {
console.log('Event: Captcha initialized', id);
}).bind('selected.iconCaptcha', function(e, id) {
console.log('Event: Icon selected', id);
}).bind('refreshed.iconCaptcha', function(e, id) {
console.log('Event: Captcha refreshed', id);
}).bind('success.iconCaptcha', function(e, id) {
console.log('Event: Correct input', id);
}).bind('error.iconCaptcha', function(e, id) {
console.log('Event: Wrong input', id);
});
});
</script>
<!-- FIN FORMULAIRE CONTACT -->
</div>
</section>
</body>
</html>
Here is the PHP function envoiformulaire.php to send the form :
<?php
header('Content-Type: text/html; charset=utf-8');
if(isset($_POST['email'])) {
$email_to = "mail#mail.com";
$email_subject = "Nouveau message web";
function died($error) {
echo "Oups! Une ou plusieurs erreurs se trouvent dans votre formulaire.<br>";
echo $error."<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('Oups! Un problème est survenu avec votre formulaire.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp ='/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'Le courriel saisi ne semble pas valide.<br />';
}
$phone_exp = "/^(\d\d\s){4}(\d\d)$/";
if(!preg_match( $phone_exp,$telephone)) {
$error_message .= 'Le numéro de téléphone saisi ne semble pas valide.<br />';
}
$string_exp = "/^[A-Za-z àèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇßØøÅåÆæœ.'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Le prénom saisi ne semble pas valide.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'Le nom saisi ne semble pas valide.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'Le message saisi ne semble pas valide.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Ci-après le formulaire complété.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Prénom: ".clean_string($first_name)."\n";
$email_message .= "NOM: ".clean_string($last_name)."\n";
$email_message .= "Courriel: ".clean_string($email_from)."\n";
$email_message .= "Téléphone: ".clean_string($telephone)."\n";
$email_message .= "Message: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'Content-Type: text/plain; charset="utf-8"'.
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
My guess is that on the contact page when i hit the SUBMIT button it activates the PHP to send the form without the CAPTCHA (method=post action="envoiformulaire.php").
I may have to add "something" to make the SUBMIT button available only with the captcha completed. But i haven't figured how to do it.
Could someone give me a hint ?
Best regards,
Frédéric.
I was in contact with the creator of icon captcha. He helped me a lot, actually more than i expected.
First mistake, i put a part of the PHP validation code page on the contact form :
if(!empty($_POST)) {
if(IconCaptcha::validateSubmission($_POST)) {
$captchaMessage = 'Le message a bien été envoyé!';
} else {
$captchaMessage = json_decode(IconCaptcha::getErrorMessage())->error;
}
}
It should to go from contact.php to envoiformulaire.php .
After that he helped me with my numbnuts php skills...
On the top of the contact page, the following code should be added :
<?php
session_start();
require('IconCaptcha-PHP/src/captcha-session.class.php');
require('IconCaptcha-PHP/src/captcha.class.php');
IconCaptcha::setIconsFolderPath('../assets/icons/');
IconCaptcha::setIconNoiseEnabled(true);
?>
And add this code (ADD) in the envoiformulaire.php :
<?php
session_start(); // ADD THIS
header('Content-Type: text/html; charset=utf-8');
require('IconCaptcha-PHP/src/captcha-session.class.php'); // ADD THIS
require('IconCaptcha-PHP/src/captcha.class.php'); // ADD THIS
IconCaptcha::setIconsFolderPath('../assets/icons/'); // ADD THIS
IconCaptcha::setIconNoiseEnabled(true); // ADD THIS
if(isset($_POST['email'])) {
$email_to = "mail#mail.com";
$email_subject = "Nouveau message web";
function died($error) {
echo "Oups! Une ou plusieurs erreurs se trouvent dans votre formulaire.<br>";
echo $error."<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('Oups! Un problème est survenu avec votre formulaire.');
}
// ADD THIS
if(!IconCaptcha::validateSubmission($_POST)) {
died('ADD YOUR ERROR MESSAGE HERE');
}
...
And now, it works great, thank you Fabian !
I hope this post will help someone in the futur.
Frédéric.
I am getting the error Failed to load resource: the server responded with a status of 404 (Not Found) and not really sure why it is happening. I have checked the routes and access of the files and everything seems fine.
My Js file looks like this:
var clContactForm = function() {
/* local validation */
$('#contactForm').validate({
/* submit via ajax */
submitHandler: function(form) {
var sLoader = $('.submit-loader');
$.ajax({
type: "POST",
url: "../inc/sendEmail.php",
data: $(form).serialize(),
beforeSend: function() {
sLoader.slideDown("slow");
},
success: function(msg) {
// Message was sent
if (msg == 'OK') {
sLoader.slideUp("slow");
$('.message-warning').fadeOut();
$('#contactForm').fadeOut();
$('.message-success').fadeIn();
}
// There was an error
else {
sLoader.slideUp("slow");
$('.message-warning').html(msg);
$('.message-warning').slideDown("slow");
}
},
error: function() {
sLoader.slideUp("slow");
$('.message-warning').html("Algo ocurrió. Por favor, inténtalo de nuevo");
$('.message-warning').slideDown("slow");
}
});
}
});
};
My php code looks like this:
<?php
// Replace this with your own email address
$siteOwnersEmail = 'myemail#gmail.com';
if($_POST) {
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Por favor, coloca tu nombre.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Por favor, pon un correo válido.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Por favor, coloca tu mensaje";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Oops! Algo ocurrió, por favor inténtalo de nuevo."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
And finally, my HTML code is this one:
<div class="row section-header" data-aos="fade-up">
<div class="col-full">
<h1 class="display-2 display-2--light">Cuéntanos un poco más de tí para que empieces a vivir la experiencia Tech Consultant</h1>
</div>
</div>
<div class="row contact-content" data-aos="fade-up">
<div class="contact-primary">
<h3 class="h6">Envíanos un mensaje</h3>
<form name="contactForm" id="contactForm" method="post" action="/index.html" novalidate="novalidate">
<fieldset>
<div class="form-field">
<input name="contactName" type="text" id="contactName" placeholder="Nombre" value="" minlength="2" required="" aria-required="true" class="full-width">
</div>
<div class="form-field">
<input name="contactEmail" type="email" id="contactEmail" placeholder="Email" value="" required="" aria-required="true" class="full-width">
</div>
<div class="form-field">
<input name="contactSubject" type="text" id="contactSubject" placeholder="Asunto" value="" class="full-width">
</div>
<div class="form-field">
<textarea name="contactMessage" id="contactMessage" placeholder="¿Qué es lo que más te interesa de Tech Consultant?" rows="10" cols="50" required="" aria-required="true" class="full-width"></textarea>
</div>
<div class="form-field">
<button class="full-width btn--primary">Enviar</button>
<div class="submit-loader">
<div class="text-loader">Enviando...</div>
<div class="s-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</fieldset>
</form>
<!-- contact-warning -->
<div class="message-warning">
¡Algo ocurrió! Por favor, intenta de nuevo.
</div>
<!-- contact-success -->
<div class="message-success">
¡Hemos recibido tu mensaje! Nuestros asesores se pondrán en contacto contigo<br>
</div>
</div> <!-- end contact-primary -->
As I mentioned before, I am getting the Failed to load resource: the server responded with a status of 404 (Not Found) error and I am not really sure why. If you can give me some insight, that would be amazing!
Thank you in advance for all of your help!!
I did some changes to your code
yes that code was not working
i sorted the same on my localhost
Please compare the code:
Updated code: ( Html and js code)
$(document).ready(function () {
/* local validation */
$('#contactForm').validate({
/* submit via ajax */
submitHandler: function(form) {
var sLoader = $('.submit-loader');
$.ajax({
type: "POST",
url: "process.php",
data: $(form).serialize(),
beforeSend: function() {
sLoader.slideDown("slow");
},
success: function(msg) {
// Message was sent
if (msg == 'OK') {
sLoader.slideUp("slow");
$('.message-warning').fadeOut();
$('#contactForm').fadeOut();
$('.message-success').fadeIn();
}
// There was an error
else {
sLoader.slideUp("slow");
$('.message-warning').html(msg);
$('.message-warning').slideDown("slow");
}
},
error: function() {
sLoader.slideUp("slow");
$('.message-warning').html("Algo ocurrió. Por favor, inténtalo de nuevo");
$('.message-warning').slideDown("slow");
}
});
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.min.js"></script>
<div class="row section-header" data-aos="fade-up">
<div class="col-full">
<h1 class="display-2 display-2--light">Cuéntanos un poco más de tí para que empieces a vivir la experiencia Tech Consultant</h1>
</div>
</div>
<div class="row contact-content" data-aos="fade-up">
<div class="contact-primary">
<h3 class="h6">Envíanos un mensaje</h3>
<form name="contactForm" id="contactForm" method="post" novalidate="novalidate">
<fieldset>
<div class="form-field">
<input name="contactName" type="text" id="contactName" placeholder="Nombre" value="" minlength="2" required="" aria-required="true" class="full-width">
</div>
<div class="form-field">
<input name="contactEmail" type="email" id="contactEmail" placeholder="Email" value="" required="" aria-required="true" class="full-width">
</div>
<div class="form-field">
<input name="contactSubject" type="text" id="contactSubject" placeholder="Asunto" value="" class="full-width">
</div>
<div class="form-field">
<textarea name="contactMessage" id="contactMessage" placeholder="¿Qué es lo que más te interesa de Tech Consultant?" rows="10" cols="50" required="" aria-required="true" class="full-width"></textarea>
</div>
<div class="form-field">
<button class="full-width btn--primary">Enviar</button>
<div class="submit-loader">
<div class="text-loader">Enviando...</div>
<div class="s-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</fieldset>
</form>
<!-- contact-warning -->
<div class="message-warning">
¡Algo ocurrió! Por favor, intenta de nuevo.
</div>
<!-- contact-success -->
<div class="message-success">
¡Hemos recibido tu mensaje! Nuestros asesores se pondrán en contacto contigo<br>
</div>
</div> <!-- end contact-primary -->
**Php Updated code**
<?php
// Replace this with your own email address
$siteOwnersEmail = 'your email id';
if($_POST) {
$message = "";
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
$error = array();
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Por favor, coloca tu nombre.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Por favor, pon un correo válido.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Por favor, coloca tu mensaje";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
//ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Oops! Algo ocurrió, por favor inténtalo de nuevo."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
Let me know if you need zip for running code will send you the same:
enter image description here
You may want to try postman to post a form data instead of using a browser. If you do that, you can find out if your PHP code works fine or not, then focus on the JavaScript code.
i have a page where i use a contact Form.
Now when i click on "submit" the form redirect me to the next page.
But i want that the page dont redirect but show the success message in my Form or load the page new and bring the message. But i dont want that it redirect to a second page..
my page:http://bit.ly/1PLbZcL
This is my html code:
<form name="htmlform" method="post" action="contact.php">
<div class="large-6 columns">
<input class="textfield" type="text" name="last_name" id="name" placeholder="Name" />
<input type="text" name="email" id="email" placeholder="E-Mail Adresse" value="" />
</div>
<div class="large-6 columns">
<input type="text" name="first_name" id="vorname" placeholder="Vorname" />
<input type="text" name="termin" id="wunschtermin" placeholder="Wunschtermin" />
</div>
<ul>
<input id="checkbox1" type="checkbox">
<p style="float:left;">Ja, ich möchte den<br>
<b>we</b>learning-Newsletter abonnieren<br> und immer auf dem Laufenden<br> bleiben.<br></p>
<input type="submit" class="submit" class="button" id="submit" value="Absenden" />
</ul>
</div>
</div>
</form>
And this is my php code:
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "dierig#be-virtual.org";
$email_subject = "website html form submissions";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['termin'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$termin = $_POST['termin']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be
valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "termin: ".clean_string($termin)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<div class="thankyou">
Vielen Dank! Wir werden uns umgehend mit Ihnen in Verbindung setzen.
Sie werden jeden Moment weitergeleitet.
</div>
<?php
header("refresh:1;index.html");
}
die();
?>
Can anyone explain me how i can realize my idea?
AJAX is what you would be looking for. I usually let the server handle data parsing and validations. This would do what you want. Just pass the form data to the requested page
function submitComment(formData)
{
var form = $("#comment_form"),
message = $("#message");
$.ajax({
url: form.attr('action'),
type: 'post',
dataType: 'json',
data: formData,
success: function(data, status, xhr) {
if(data.error)
{
...
Error on page requested
...
}
else
{
...
No error on page requested
...
}
},
error: function(xhr, status, errorThrown) {
message.removeClass().addClass('error').html("There was an error processing the form! Error: " + status + " " + errorThrown + "<br>").fadeIn();
}
});
}
with ajax, something like this, but i dont tested it, so there can be some mistakes, anyway, take look at this:
http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
$('form').submit(function(e)){
e.preventDwfault();
$.post('contact.php',{
last_name : $('#name').val(),
email : $('#email').val(),
firstname : $('#vorname').val(),
termin : $('#wunschtermin').val()
},function(data){
$('#your_alert_span_in_form').html(data);
})
})
I have this form, it works perfectly but when submitted/failed it swaps to another page where the message is showed.
HTML
<form action="envio.php" method="post">
<label>Nombre </label>
<input type="text" name="name"><br>
<label>Email</label>
<input type="text" name="email"><br>
<label>Teléfono</label>
<input type="text" name="phone"><br>
<label>Mensaje</label>
<textarea name="message"></textarea><br>
<input id="submit" type="submit" name="submit" value="Enviar">
</form>
envio.php
if(isset($_POST['submit'])){
$to = "email#gmail.com"; // email destinatario
$from = $_POST['email']; // email del cliente
$name = $_POST['name'];
$phone = $_POST['phone'];
$mes = $_POST['message'];
$subject = "Formulario web";
$subject2 = "Copia de su formulario de consulta";
$message = $name . " con número de teléfono: " . $phone . " escribió lo siguiente:" . "\n\n" . $_POST['message'];
$message2 = "Aquí tiene una copia de su mensaje " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
$success = (preg_match("/^[0-9]{9}$/",$phone) && preg_match("/^[a-zA-Z]*$/",$name) && $mes!='' && filter_var($from, FILTER_VALIDATE_EMAIL));
if ($success){
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // copia para el cliente
echo "Formulario enviado. Muchas gracias " . $name . ", en breve contactaremos con usted.";
}
else {
echo "Lo sentimos, se ha producido un error al enviar el formulario, revise su contenido y vuelva a intentarlo.";
}}
I just want to show the messages in the if/else under the 'send' button after click it, without refresh, I think it can be done with JQuery/Vanilla but I have no clue. How can JS know if the form was submitted successfully? How can I tell JS where to insert the message?
Further to my comments and because it's hard to explain in such a little space:
page1.php
<!-- Name the form myform as an id -->
<form action="page2.php" method="post" id="myform">
<label>Nombre </label>
<input type="text" name="name"><br>
<label>Email</label>
<input type="text" name="email"><br>
<label>Teléfono</label>
<input type="text" name="phone"><br>
<label>Mensaje</label>
<textarea name="message"></textarea><br>
<input id="submit" type="submit" name="submit" value="Enviar">
</form>
<!-- Invisible response container -->
<div id="response"></div>
<script>
$("#myform").submit(function() {
$.ajax({
// PHP page
url : 'page2.php',
// Takes all data from form
data: $("#myform").serialize(),
// Puts response into the container
success: function(response) {
$("#response").html(response);
}
});
// This stops the page from reloading on submit
return false;
});
</script>
page2.php
if(isset($_POST['submit'])){
$to = "email#gmail.com"; // email destinatario
$from = $_POST['email']; // email del cliente
$name = $_POST['name'];
$phone = $_POST['phone'];
$mes = $_POST['message'];
$subject = "Formulario web";
$subject2 = "Copia de su formulario de consulta";
$message = $name . " con número de teléfono: " . $phone . " escribió lo siguiente:" . "\n\n" . $_POST['message'];
$message2 = "Aquí tiene una copia de su mensaje " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
$success = (preg_match("/^[0-9]{9}$/",$phone) && preg_match("/^[a-zA-Z]*$/",$name) && $mes!='' && filter_var($from, FILTER_VALIDATE_EMAIL));
if ($success){
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // copia para el cliente
echo "Formulario enviado. Muchas gracias " . $name . ", en breve contactaremos con usted.";
}
else {
echo "Lo sentimos, se ha producido un error al enviar el formulario, revise su contenido y vuelva a intentarlo.";
}
}
So i've been working on this for days and done lots of research over internet with no sucess, so i'm giving a try to understand if anyone can help me.
I've this form :
<!-- Modal form contactjobApply starts -->
<div class="modal hide fade" id="contactformjobapply" tabindex="-1" role="dialog" aria-labelledby="contactformLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><img src="images/bt_close_form.png"></button>
<h1 class="modal-title" id="contactformLabel">NOUS CONTACTER POUR :</h1>
<p class="forminformation">Sécrétaire réceptionniste français anglais</p>
</div>
<div class="modal-body">
<form class="form-horizontal" method="POST" enctype="multipart/form-data" action="formmail_apply.php" autocomplete="on">
<input type="hidden" name="Subject" value="Postulation à l'offre d'emploi">
<fieldset>
<div class="control-group">
<label class="control-label" for="textinputprenom">Prénom*</label>
<div class="controls">
<input id="textinputprenom" name="formpnom" type="text" placeholder="Votre prénom" required autofocus>
</div>
</div>
<div class="control-group">
<label class="control-label" for="textinputnom">Nom*</label>
<div class="controls">
<input id="textinputnom" name="formnom" type="text" placeholder="Votre Nom">
</div>
</div>
<div class="control-group">
<label class="control-label" for="textinputmail">Adresse e-mail*</label>
<div class="controls">
<input id="textinputmail" name="formmail" type="email" placeholder="Votre adresse e-mail" required title="Un adresse e-mail valid. Ex:. moi#gmail.com">
</div>
</div>
<div class="control-group">
<label class="control-label" for="textinputcontact">Téléphone*</label>
<div class="controls">
<input id="textinputcontact" name="formcontact" type="tel" placeholder="Votre contact par téléphone ou natel" maxlength="10" pattern="[10|0][0-9]{9}" required title="Votre nº de téléphone. Ex:. 0781231212 ou 0221231212">
</div>
</div>
<div class="control-group">
<label class="control-label" for="textinputprofession">Profession*</label>
<div class="controls">
<input id="textinputprofession" name="formprofession" type="text" placeholder="Votre profession actuelle" required>
</div>
<div class="control-group fileupload">
<label class="control-label" for="filebutton">Votre dossier*</label>
<div class="controls">
<a class="file-input-wrapper btinput">CHOISIR FICHIER
<p class="help-block2">Pas de fichier téléchargé</p>
<input id="filebutton" type="file" title="Choisir votre CV" name="filebutton" accept="text/plain,application/pdf,application/msword,application/rtf" allow="text/plain,application/pdf,application/msword,application/rtf" required placeholder="Pas de fichier téléchargé">
</a>
<p class="help-block">NB: Envoyez uniquement des fichiers au format DOC / PDF / TXT - 1Mo MAX</p>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="textarea" required>Lettre de motivation*</label>
<div class="controls">
<textarea id="textarea" name="formmessage" placeholder="Votre lettre de motivation" required></textarea>
</div>
</div>
<button type="submit" class="bt_sendform">ENVOYER</button>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<!-- Modal form contactjobApply ends -->
And this PHP :
<meta charset="UTF-8">
<?php
// Pear library includes
// You should have the pear lib installed
include_once('Mail.php');
include_once('Mail_Mime/mime.php');
// infos from form
$email_to = "your#mail.com";
$email_subject = "Nouveau message d'yourwebsite.com";
$upload_folder = './uploads/'; //<-- this folder must be writeable by the script
// Check for safari
function died($error) {
// your error code can go here
echo "Vos informations ne sont pas correctes<br><br><br>";
echo "Remplissez les champs suivants :<br><br>";
echo $error."<br><br>";
echo "Remplissez les champs en manque<br><br>";
die();
}
// validation expected data exists
if(!isset($_POST['formpnom']) ||
!isset($_POST['formnom']) ||
!isset($_POST['formmail']) ||
!isset($_POST['formcontact']) ||
!isset($_POST['formprofession']) ||
!isset($_POST['formmessage'])) {
died('Il semble manquer des informations');
}
//Get the uploaded file information
$name_of_uploaded_file = basename($_FILES['filebutton']['name']);
//get the file extension of the file
$type_of_uploaded_file = substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file = $_FILES["filebutton"]["size"]/1024;//size in KBs
//Settings
$max_allowed_file_size = 1024; // size in KB
$allowed_extensions = array("txt", "doc", "docx", "pdf");
//Validations
if($size_of_uploaded_file > $max_allowed_file_size ) {
$error_message .= "\n La taille du fichier doit être plus petite";
}
//------ Validate the file extension -----
$allowed_ext = false;
for($i=0; $i<sizeof($allowed_extensions); $i++) {
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0) {
$allowed_ext = true;
}
}
if(!$allowed_ext) {
$error_message .= "\n Ce fichier n'est pas valable. ".
" Télécharger uniquement les fichiers suivants : ".implode(',',$allowed_extensions);
}
//copy the temp. uploaded file to uploads folder
$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
$tmp_path = $_FILES["filebutton"]["tmp_name"];
if(is_uploaded_file($tmp_path)) {
if(!copy($tmp_path,$path_of_uploaded_file)) {
$error_message .= "\n Votre fichier n'est pas attaché, un problème est la cause";
}
}
// declare variables
$first_name = $_POST['formpnom']; // required
$last_name = $_POST['formnom']; // required
$email_from = $_POST['formmail']; // required
$telephone = $_POST['formcontact']; // required
$profession = $_POST['formprofession']; // required
$comments = $_POST['formmessage']; // required
$error_message = "";
// Check for safari
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'Un adresse e-mail valid. Ex:. moi#gmail.com<br>';
}
$phone_exp = '/^[10|0][0-9]{9}$/';
if(!preg_match($phone_exp,$telephone)) {
$error_message .= 'Votre nº de téléphone. Ex:. 0781231212 ou 0221231212<br>';
}
$string_exp = "/^[A-Za-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÕÒÓÔÖÙÚÛÜŸŒÆàáâãäåçèéêëìíîïðòóôõöùúûüýÿœæ .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= "Votre prénom n'est pas valide<br>";
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= "Votre nom n'est pas valide<br>";
}
if(!preg_match($string_exp,$profession)) {
$error_message .= "Votre profession n'est pas valide<br>";
}
if(strlen($comments) < 2) {
$error_message .= "Vous n'avez pas de message<br>";
}
if(strlen($error_message) > 0) {
died($error_message);
}
// Message before mail
$email_message .= "Prénom : ".clean_string($first_name)."\n";
$email_message .= "Nom : ".clean_string($last_name)."\n";
$email_message .= "Adresse e-mail: ".clean_string($email_from)."\n";
$email_message .= "Téléphone : ".clean_string($telephone)."\n";
$email_message .= "Profession : ".clean_string($profession)."\n";
$email_message .= "Message : ".clean_string($comments)."\n";
// create email headers
#mail($email_to, $email_subject, $email_message, $headers);
header("Location: http://bpoeta.net/pen/anj");
//send the email
$message = new Mail_mime();
$message->setTXTBody($email_message);
$message->addAttachment($path_of_uploaded_file);
$body = $message->get();
$extraheaders = array("From"=>$email_to, "Subject"=>$email_subject,"Reply-To"=>$email_from);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($email_to, $headers, $body);
//redirect to 'thank-you page
header('Location: http://bpoeta.net/pen/anj');
?>
I've been able to make it work with input validation, and sending back to my chosen link after a sent mail, but sundenly it stop work and I can't achieve how to attach a file to a mail and send it with the mail.
I've been using bootstrap for most configurations and I would like to be able, if possible, after sending the email, to keep in the modal layer of the form, with an alert message, or send it back to the index page. and of course be able to send a file attached with the email.
I would really appreciate your help on this
got the answer :
<meta charset="UTF-8">
<?php
// files sent
if(isset($_FILES) && (bool) $_FILES) {
// define allowed extensions
$allowedExtensions = array("pdf","doc","docx","txt");
$files = array();
$maxsize = 1048576;
// loop through all the files
foreach($_FILES as $name=>$file) {
// define variables
$file_name = $file['name'];
$temp_name = $file['tmp_name'];
// check file allow
$path_parts = pathinfo($file_name);
$ext = $path_parts['extension'];
$sizeu = filesize($file);
$fsize = $file['size'];
if(!in_array($ext,$allowedExtensions)) {
die("Le fichier $file_name a le format $ext qui n'est pas autorisé ou aucun fichier a été uploader.<br><br>Retournez à la page précédente");
}
if(($fsize >= $maxsize) || ($fsize == 0)) {
die("Le fichier $file_name est de $fsize Mo .<br><br>Sa taille ne doit pas dépasser 1 Mo.<br><br>Retournez à la page précédente");
}
// move the file to server
$server_file = "$path_parts[basename]";
move_uploaded_file($temp_name, $server_file);
// add file to arrays
array_push($files,$server_file);
}
// Check for safari
function died($error) {
// your error code can go here
echo "Vos informations ne sont pas correctes<br><br><br>";
echo "Remplissez les champs suivants :<br><br>";
echo $error."<br><br>";
echo "Remplissez les champs en manque<br><br>";
die();
}
// validation expected data exists
if(!isset($_POST['formnom']) ||
!isset($_POST['formmail']) ||
!isset($_POST['formsubject']) ||
!isset($_POST['formmessage'])) {
died('Il semble manquer des informations');
}
// email fields: to, from, subject, and so on
$name = $_POST['formnom']; // required
$to = "your#mail.com";
$email_fromto = "no-reply#mail.com";
$from = $_POST['formmail'];
$subject = "E-mail envoyé de yourwebsite.com";
$formsubject = $_POST['formsubject']; // required
$msg = $_POST['formmessage'];
$error_message = "";
$headers = 'From: '.$email_fromto."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Check for safari
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$from)) {
$error_message .= 'Un adresse e-mail valid. Ex:. moi#gmail.com<br>';
}
$string_exp = "/^[A-Za-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÕÒÓÔÖÙÚÛÜŸŒÆàáâãäåçèéêëìíîïðòóôõöùúûüýÿœæ .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= "Votre nom n'est pas valide<br>";
}
if(!preg_match($string_exp,$formsubject)) {
$error_message .= "Votre objet n'est pas valide<br>";
}
if(strlen($msg) < 2) {
$error_message .= "Vous n'avez pas de message<br>";
}
if(strlen($error_message) > 0) {
died($error_message);
}
// Message before mail
$mail_message = "Contenu de ce message\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$mail_message .= "Nom : ".clean_string($name)."\n";
$mail_message .= "Adresse e-mail: ".clean_string($from)."\n";
$mail_message .= "Objet : ".clean_string($formsubject)."\n";
$mail_message .= "Message : ".clean_string($msg)."\n";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers boundary
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
// headers plain
$message ="\n\n--{$mime_boundary}\n";
$message .="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .="Content-Transfer-Enconding: 7bit\n\n" . $mail_message . "\n\n";
$message .= "--{$mime_boundary}\n";
// loop
foreach($files as $file) {
$aFile = fopen($file,"rb");
$data = fread($aFile,filesize($file));
fclose($aFile);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n";
$message .= " name=\"$file\"\n";
$message .= "Content-Disposition: attachment;\n";
$message .= " filename=\"$file\"\n";
$message .= "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = #mail($to, $subject, $message, $headers);
if ($ok) {
echo '
<script type="text/javascript">
document.location = "http://yourwebsite.com"
</script>
';
} else {
echo "<p>Votre e-mail n'a pas été envoyé, un problème dans votre terminal l'empêche</p>";
}
die();
}
?>
and for the form:
<form class="form-horizontal" method="POST" action="formmail.php" autocomplete="on" enctype="multipart/form-data" accept-charset="utf-8">
Thanks a lot for the guys who helped me :)
It's hard to understand php when you're not good on math, and you only into webdesign (I mean design).
Cheers all and hope it helps others!