Form "From" field appears as server account name

Asked

Viewed 51 times

0

hello! I have a problem with my contact form. The PHP that processes the data and sends it to my email, returns the "From" field with my server user address and not as the sender address.

<?php
if(isset($_POST['contact_name']) != ""){
            $to = "[email protected]";
            $from =  $_POST["contact_email"];
            $message = "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Nome: </strong>".$_POST["contact_name"]."<br />";
            $message .= "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Email: </strong>".$_POST["contact_email"]."<br />";
            $message .= "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Telefone: </strong>".$_POST["contact_phone"]."<br />";
            $message .= "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Cotacao para: </strong>".$_POST["contact_servico"]."<br />";
            $message .= "&nbsp;&nbsp;&nbsp;&nbsp; <strong>Mensagem: </strong>".$_POST["message"]."<br />";
            $subject = 'Solicitação de cotação';        
            $headers = "De: ".$_POST["contact_email"]."\n";
            $headers .= "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

            $send = mail($to,$subject,$message,$headers);



    if($send)
    {
        echo "Agradecemos sua solicitação. Entraremos em contato o mais breve possível.";
    }
    else
    {
        echo "Erro no envio da mensagem. Por favor, verifique os campos de preenchimento.";
    }
}


if(isset($_POST['subscribe_name']) != ""){
            $to = "[email protected]";
            $from =  $_POST["subscribe_email"];
            $message = "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Nome: </strong>".$_POST["subscribe_name"]."<br />";
            $message .= "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Email: </strong>".$_POST["subscribe_email"]."<br />";
            $subject = 'Inscrição';     
            $headers = "De: ".$_POST["subscribe_email"]."\n";
            $headers .= "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

            $send = mail($to,$subject,$message,$headers);



    if($send)
    {
        echo "Agradecemos sua solicitação.";
    }
    else
    {
        echo "error";
    }
}


?>
<form class="contact-form" name="contact_form" id="contact_form" method="post" action="process.php" onSubmit="return false">
                                <div class="row">
                                    <div class="col-md-6">
                                        <input type="text" data-delay="300" placeholder="Seu nome" name="contact_name" id="contact_name" class="input">
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" data-delay="300" placeholder="Seu E-mail" name="contact_email" id="contact_email" class="input">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <input type="text" data-delay="300" placeholder="Seu telefone" name="contact_phone" id="contact_phone" class="input">
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" data-delay="300" placeholder="Cotacao para" name="contact_servico" id="contact_servico" class="input">
                                    </div>
                                </div>
                                <textarea data-delay="500" class="required valid" placeholder="Mensagem" name="message" id="message"></textarea>
                                <button class="btn btn-primary" name="" type="submit" data-text="Enviar" onClick="validateContact();">Enviar</button>
                            </form>
  • Take a look at the "name" property of the inputs, maybe it’s the other way around.

1 answer

1


The field FROM should be in English, the header of your email is going as "De" (in Portuguese).

Change this line:

$headers = "De: ".$_POST["contact_email"]."\n";

For this:

$headers = "From: ".$_POST["contact_email"]."\n";

Change this line:

$headers = "De: ".$_POST["subscribe_email"]."\n";

For this:

$headers = "From: ".$_POST["subscribe_email"]."\n";
  • Thanks Bruno! Gave right. That’s right.

  • Not for nothing @Silvanacampos. Then don’t forget to mark the answer as a served solution.

Browser other questions tagged

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