Send an e-mail message to customers who responded to my website form

Asked

Viewed 51 times

3

I have the following code to send the responses of a form from my website to my email:

<?php

//
//Variáveis
$n_nome = $_POST['n-nome'];
$n_email = $_POST['n-email'];
$n_fone = $_POST['n-fone'];
$n_msg = $_POST['n-msg'];

$data_envio = date('d/m/Y');
$hora_envio = date('H:i:s');

//
// Configuração do e-mail
  $arquivo = "
<html>
    <h1>NOVA MENSAGEM RECEBIDA VIA SITE</h1>

    <p>Nome: <b>$n_nome</b></p>
    <p>E-mail: <b>$n_email</b></p>
    <p>Telefone: <b>$n_fone</b></p>
    <p>Mensagem: <br> <b>$n_msg</b></p>
</html>
";

//
//enviar
  $emailenviar = "[email protected]";
  $destino = $emailenviar;
  $assunto = "[SITE CONTATO] $n_nome";

  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
  $headers .= 'From: Meu Site <[email protected]>';

  $enviaremail = mail($destino, $assunto, $arquivo, $headers);
  if($enviaremail){
  $mgm = "MENSAGEM RECEBIDA COM SUCESSO!";
  echo " <meta http-equiv='refresh' content='2;URL='> "; // Configurar página de destino
  } else {
  $mgm = "ERRO AO RECEBER MENSAGEM!";
  echo "<meta http-equiv='refresh' content='2;URL='>";
  }
?>

Now, when I answer the message in my email I have to copy the email form and paste in the appropriate field. He always tries to answer to There’s a way to pre-defame that when I answer he’ll already put the $n_email as a recipient?

1 answer

0


The From: should be the sender and not a fixed email:

$headers .= 'From: Meu Site <[email protected]>';

Should be:

$headers .= 'From: ' . $n_nome . ' <' . $n_email . '>';

Note that you can also use Reply-To:, that is to define that the sender is one, but when answering the Reply-To will give preference to the email set in it (this may not work on some more archaic web email clients such as squiremail), so it would look like this:

$headers .= "From: Meu Site <[email protected]>\r\n";
$headers .= 'Reply-To: ' . $n_nome . ' <' . $n_email . '>';
  • Okay. I switched to $headers .= 'From: $n_nome <$n_email>';. But at the time of answering her in the email is "From: $n_name, with the email: [email protected]".

  • @Marcoslichtenfels You copied exactly as I did, or you changed the quotes?

  • 1

    It worked. I copied exactly your answer and it worked. Thank you!

Browser other questions tagged

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