Reply (in e-mail) the PHP form response to a different email

2

I have the following code to send the responses of a form from my site 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 reply to the message in my email I have to copy the email form and paste it into the appropriate field. It always tries to respond to the There is how to leave pre-defined that when I answer it already put $n_email as the recipient?

    
asked by anonymous 17.05.2018 / 22:48

1 answer

1

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, set the sender to be one, but at the moment of responding Reply-To will give preference to the email set in it (this may not work for some email clients web more archaic, like squiremail), then it would look like this:

$headers .= "From: Meu Site <[email protected]>\r\n";
$headers .= 'Reply-To: ' . $n_nome . ' <' . $n_email . '>';
    
17.05.2018 / 23:01