1
I have the following code
<?php
require_once('PHPMailer-master/PHPMailerAutoload.php');
PHP_OS == "Linux" ? $quebra_linha = "\n" : $quebra_linha = "\r\n";
//$emp = $_POST["empresa"];
$nome = trim($_POST["nome"]);
$tel = $_POST["telefone"];
$cid = $_POST["cidade"];
//$ass = $_POST["assunto"];
//$msg = $_POST["mensagem"];
switch ($cid) {
case "ipatinga":
$destino = "[email protected]";
break;
case "fabriciano":
$destino = "[email protected]";
break;
case "timoteo":
$destino = "[email protected]";
break;
}
$email = "<br><b>NOME:</b> ".$nome."<br><b>TELEFONE:</b> ".$tel." <br><b>CIDADE:</b> ".$cid."</body></html>";
$mail = new PHPMailer();
$mail->IsMail();
//$mail->SetFrom('[email protected]', 'Thiago Londe');
$mail->SetFrom($eml, $nom);
$mail->Subject = "Agendamento de visita";
$mail->MsgHTML($email);
//$mail->AddAddress($destino, "Thiago Londe");
$mail->AddAddress($destino, utf8_decode('Unimed'));
if (!$mail->send()) {
$msgerro = "Não foi possível enviar sua mensagem de contato. Tente novamente dentro de alguns instantes.";
} else {
$msgerro = "Sua mensagem de contato foi enviada com sucesso!";
}
if($mail->send()) { ?>
<script language='javascript'>
alert('<?php echo $msgerro; ?>');
window.open('../#agendar-visita','_self');
</script>
I would like to know some way to display a submission confirmation modal as soon as the user submits the form.
Any suggestions?
Thanks Kenny Rafael. But how can I do this inside php? I have this: if (!$mail->send()) { $msgerro = "Could not send your contact message. Try again in a few moments." ; } Else { $msgerro = "Your contact message has been sent successfully!" ; } .
– Marcelo Victor
I’ll edit it to make it clearer!
– Kenny Rafael
You are already setting the message, regardless of error or not, in this case, just give echo inside the modal as in the example, what I changed was actually just enter your upload code before displaying the content.
– Kenny Rafael
I got Kenny Rafael. Now I have another question. My form is validating to see if the fields have all been filled out. My modal is appearing even if the fields are not filled in. How to make it appear only if all fields are filled in? I left it like this: $('form button[type="Submit"]'). on('click', Function() { $('#modal-mail'). modal('show'); });
– Marcelo Victor
The ideal is that your modal always open with the information of what happened, in this case I upgraded the code, take a look!
– Kenny Rafael