1
Hello, my code sends the email to my email box, but my "Alert" does not appear when I click send
Another problem is that in my inbox the email of the sender that appears is not the email of the field that was filled in the form (appears the email that appears is the server).
It is correct the sender’s email that appears in the server’s inbox ?
If not, can you change to receive the e-mail that was filled? And I also could not 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');
}
?>
That’s right, thank you (:
– Estácio Di Fabio
@Stable, or use a
header( "refresh:5;url=contato.php" )
if you want to avoid failure in case js is disabled.– Papa Charlie