I wanted to know if the PHP setup I'm doing for the submission in a form is well-armed. From what I read in the documentation I have to download two PHP files, the Class.phpmailer.php and the SMTP.php and link them the way I'm doing with a require, both files are in the same root where the shipment would be. php that the file that I write below. On the other hand, I do not have a clear idea of what kind of data I need to have from the client so that the data reaches their account. In this example I'm doing with data from my hotmail account to do those tests.
On the other hand I'm doing a script where I link the PHP file through Ajax I wanted to know if it is correctly armed.
<?php
function envioMail(){
$ecommerce = $_POST["Ecommerce"];
$nombre = $_POST["Nombre"];
$telefono = $_POST["Telefono"];
$email = $_POST["Email"];
require("class.phpmailer.php");
require("SMTP.php");
require("Exception.php");
$mail = new PHPMailer(true);
$mail->Mailer = "smtp";
$mail->SMTPAuth = true;
$mail->Host = "smtp.live.com"; // A RELLENAR. Aquí pondremos el SMTP a utilizar. Por ej. mail.midominio.com smtp.gmail.com
$mail->Username = "[email protected]"; // A RELLENAR. Email de la cuenta de correo. [email protected] La cuenta de correo debe ser creada previamente.
$mail->Password = ""; // A RELLENAR. Aqui pondremos la contraseña de la cuenta de correo
$mail->From = "[email protected]"; // A RELLENAR Desde donde enviamos (Para mostrar). Puede ser el mismo que el email creado previamente.
$mail->FromName = "Mariano"; //A RELLENAR Nombre a mostrar del remitente.
$mail->Subject = "Mensaje de Welivery"; // Este es el titulo del email.
$mail->AddAddress("[email protected]");/*email de CM*/
$body =
"
Se ha informado la descarga del siguiente resultado: $codigoAlerta
Muchas gracias
Equipo PfAst
Pfizer
";
$mail->Body = $body;
$mail->CharSet = 'UTF-8';
$mail->Send();
}
if($_POST){
switch($_POST["tarea"]){
case "envio":envioMail();break;
}
}
?>
$(function(){
var errorMessage = $(".errorMessage");
var validMessage = $(".validMessage");
function clearInputs(){
errorMessage.html("");
validMessage.html("");
}
$(".inputValidation").on("click", function(e){
clearInputs();
});
$("#btnSubmit").on("click", function(e){
clearInputs();
var hasError = false;
var hasvalid = true;
var exprMail= /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
$(".inputValidation").each(function(){
var $this = $(this);
if($this.attr("name") === "email"){
if( !(exprMail.test($this.val()) ) ) {
hasError = true;
$this.addClass("inputError");
errorMessage.html("<p>Por favor, ingrese un email valido.</p>");
e.preventDefault();
}
}
if($this.val() == ""){
hasError = true;
$this.addClass("inputError");
errorMessage.html("<p>Por favor, complete los siguientes campos.</p>");
e.preventDefault();
}
if($this.val() != ""){
$this.removeClass("inputError");
}else{
return true;
}
});
errorMessage.slideDown(700);
if(hasError == false){
Ecommerce = document.getElementById("exampleInputEcommerce").value;
Nombre = document.getElementById("exampleInputNombre").value;
Telefono = document.getElementById("exampleInputPhone").value;
Email = document.getElementById("exampleInputEmail1").value;
data2= {
ecommerce:Ecommerce,
nombre:Nombre,
telefono:Telefono,
email:Email,
tarea: "envio"
};
$.ajax({
type: "POST",
url:"envio.php",
data: data2,
success:function(data){
/*$('#respuesta').fadeOut('fast').html(
"Gracias, se a enviado su mensaje"
);*/
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('.validMessage').fadeOut('fast').html(
"Gracias, se a enviado su mensaje"
);
$(".inputValidation").val("");
}
});
}
}); //Form .submit
});