Sending Email with PHP

2

I have a website where the server has just blocked the email sending from another provider, only allowing the email with the domain itself, I made the change from FROM to an email from my domain and it worked, but the received e-mail appears with the sender this email that I changed, I would like to know if it has to change to appear the filled e-mail in the form, remembering that it has to be only in the visualization, since the sending has to be with the provider's email because another is blocked, the code I'm using follows:

<?php

$nome = $_POST['nome'];
$email = $_POST['email'];
$assunto = $_POST['assunto'];
$msg = $_POST['mensagem'];

$to = "[email protected]";

$subject = "Formulário de Contato";

$menssage = "<strong> Nome: </strong> $nome <br/><br/> <strong> E-mail: </strong> $email <br/><br/> <strong> Assunto: </strong> $assunto <br/><br/> <strong> Mensagem: </strong> $msg";

$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
$header .= "From: $to\n";

mail($to, $subject, $menssage, $header);

echo "Mensagem enviada com sucesso";

?>
    
asked by anonymous 18.01.2017 / 13:46

1 answer

2

Try to test like this:

<?php

$nome = $_POST['nome'];
$email = $_POST['email'];
$assunto = $_POST['assunto'];
$msg = $_POST['mensagem'];

$to = "[email protected]";

$subject = "Formulário de Contato";

$menssage = "<strong> Nome: </strong> $nome <br/><br/> <strong> E-mail: </strong> $email <br/><br/> <strong> Assunto: </strong> $assunto <br/><br/> <strong> Mensagem: </strong> $msg";

$emailsender = "[email protected]";

$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
$header .= "From: $to\n";

mail($to, $subject, $menssage, $header, "-r".$emailsender);

echo "Mensagem enviada com sucesso";

?>

Special attention to the variable $ emailsender , you should place an existing email in your domain, eg: [email protected].

Another note: In Linux it is mandatory to use the -r (concatenation of "From in the send line") due to the sending through Postfix.

Any questions, just talk.

    
18.01.2017 / 14:09