I am sending an email in PHP using the php mailer library but the problem is that I want the button to say loading while the mail is being sent and after it says your mail has been sent successfully, check the inbox
PHP code:
//send mails
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->Helo = "smtp.gmail.com"; // nombre del dominio de primer nivel
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com"; //servidor donde se enviara el email
$mail->Port = "465";
$mail->Username = "[email protected]"; //cuenta que enviara los correos
$mail->Password = "123456"; //contraseña de la cuenta
$mail->From = "[email protected]"; // correo de quien lo envia
$mail->FromName = 'titulo'; //nombre o titulo referente al destinatario
$mail->Subject = 'sub'; //titulo que aparece despues de quien lo envia
$mail->IsHTML(true);
$mail->AddAddress([email protected]); //para quien va
$mail->Body = "ok"; //cuerpo del mensaje
$mail->CharSet = 'UTF-8';
if(!$mail->Send()){
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
/* aqui el mensaje que se a enviado exitosamente */
}
JavaScript code:
var url = "a.php";
$.ajax({
type: "POST",
url: url,
data: $("#3as3dsad22s1").serialize(),
success: function(data) {
$("#asd2a2sd23333asd").html(data);
}
});
return false;
I appreciate the help
You could just use the
beforeSend()
ajax function to add the text toloading
the button and then, once it's done executing, display the message whether it's successful or not.HTML
JavaScript
PHP
I hope it helps you. I think it would be something like this:
Suppose your button is:
So in your method: