The form's "From" field appears as the server account name

0

Hello! I have a problem with my contact form. PHP that processes the data and sends it to my email, returns the "From" field with my server's user address and not as the sender's 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>
    
asked by anonymous 06.07.2017 / 18:15

1 answer

1

The FROM field should be in English, the header of your email is going to be " De ". >

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";
    
06.07.2017 / 18:27