Mail to same page in php

Asked

Viewed 19 times

0

People I am with a certain doubt and wanted more updates I have the following code

// VALIDAÇÃO DE DADOS

$chCC_Nome=$_POST['chCC_Nome'];
$chCC_Assunto=$_POST['chCC_Assunto'];
$chCC_Email=$_POST['chCC_Email'];
$chCC_Mensagem=$_POST['chCC_Mensagem'];

// ENVIAR DADOS

mail("Contato <[email protected]","$chCC_Assunto","
NOME DE IDENTIFICAÇÃO.: $chCC_Nome
EMAIL ELETRÔNICO.: $chCC_Email
MENSAGEM: $chCC_Mensagem","FROM: $chCC_Nome < $chCC_Email >");
<form name="form" accept-charset="ISO-8859-1" method="post" action="?st=contato" id="mainform">
<input name="chCC_Assunto" type="hidden" id="chPP_Assunto" value="PG CTS" />
<input name="chCC_Nome" type="text" placeholder="Nome Completo" required />
<input name="chCC_Email" type="text" placeholder="Endereço Eletrônico" required  />
<input name="chCC_Email" type="text" placeholder="Mensagem" required  />
<input class="submit" type="submit" value="Enviar" />

How do I send to the same page without redirecting to another and inform a message saying it was sent successfully!

Thank you in advance.!

1 answer

1


According to the documentation of the mail(), he will return TRUE if the email is successfully accepted to be sent, otherwise it will return FALSE. That is, even if the email is accepted to be sent, it does not necessarily mean that it has reached its destination. So what you might be doing is putting one if to check if it will return TRUE or FALSE and make it display a message next using echo()

Code:

// VALIDAÇÃO DE DADOS

$chCC_Nome=$_POST['chCC_Nome'];
$chCC_Assunto=$_POST['chCC_Assunto'];
$chCC_Email=$_POST['chCC_Email'];
$chCC_Mensagem=$_POST['chCC_Mensagem'];

// ENVIAR DADOS

if(@mail("Contato <[email protected]","$chCC_Assunto","
   NOME DE IDENTIFICAÇÃO.: $chCC_Nome
   EMAIL ELETRÔNICO.: $chCC_Email
   MENSAGEM: $chCC_Mensagem","FROM: $chCC_Nome < $chCC_Email >")){
   echo "Email enviado com sucesso";
}else{
   echo "Email não enviado";
}

<form name="form" accept-charset="ISO-8859-1" method="post" action="?st=contato" id="mainform">
<input name="chCC_Assunto" type="hidden" id="chPP_Assunto" value="PG CTS" />
<input name="chCC_Nome" type="text" placeholder="Nome Completo" required />
<input name="chCC_Email" type="text" placeholder="Endereço Eletrônico" required  />
<input name="chCC_Email" type="text" placeholder="Mensagem" required  />
<input class="submit" type="submit" value="Enviar" />
  • Thanks Tales for managing to remove my doubt, I was with this super doubt a long time, I hope it helps other people also this post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.