Hello, my code sends the email to my email box, however my "alert" does not appear when I click on send
Another problem is that in my inbox the sender's email that appears is not the email of the field that was filled in the form (the email that appears is that of the server appears).
Correct the sender's email that appears in the server's inbox ?
If not, can you change the email that has been filled in? And I also have not been able to get my attachment sent.
<?php
$arquivo = isset($_FILES["arquivo"]) ? $_FILES["arquivo"] : FALSE;
$headers = "Content-type: text/plain; charset=utf-8\r\n";
$nome = $_POST['nome'];
$assunto = $_POST['assunto'];
$email_from = $_POST['email'];
$email = "[email protected]";
$mensagem = "<br> <strong>Mensagem: </strong>".$_POST['texto'];
if(file_exists($arquivo["tmp_name"]) and !empty($arquivo))
{
$fp = fopen($_FILES["arquivo"]["tmp_name"],"rb");
$anexo = fread($fp,filesize($_FILES["arquivo"]["tmp_name"]));
$anexo .= base64_encode($anexo);
fclose($fp);
$anexo .= chunk_split($anexo);
$boundary = "XYZ-" . date("d-m-Y-i:s") . "-ZYX";
$mens = "--$boundary\n";
$mens .= "Content-Transfer-Encoding: 8bits\n";
$mens .= "Content-Type: text/html; charset=\"UTF-8\"\n\n"; //plain
$mens .= "$mensagem\n";
$mens .= "--$boundary\n";
$mens .= "Content-Type: ".$arquivo["type"]."\n";
$mens .= "Content-Disposition: attachment; filename=\"".$arquivo["name"]."\"\n";
$mens .= "Content-Transfer-Encoding: base64\n\n";
$mens .= "$anexo\n";
$mens .= "--$boundary--\r\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "De \"$nome\"\r\n";
$headers .= "E-mail: \"$email_from\" \r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
$headers .= "$boundary\n";
//envio o email com o anexo
mail($email,$assunto,$mens,$headers);
?>
<script type="text/javascript">
alert("Email enviado com Sucesso!");
</script>
<?php
header('location: contato.php');
}
//se não tiver anexo
else
{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "De \"$nome\"\r\n ";
$headers .= "E-mail: \"$email_from\" \r\n";
//envia o email sem anexo
mail($email,$assunto,$mensagem, $headers);
?>
<script type="text/javascript">
alert("Email enviado com Sucesso!");
</script>
<?php
header('location: contato.php');
}
?>