<?php
// inclui o arquivo onde está a funçao de conexão
include("global.inc");
$email = $_POST["email"];
$assunto = $_POST["assunto"];
$mensagem = $_POST["mensagem"];
$attach = $_FILES["attach"]["tmp_name"];
$attach_name = $_FILES["attach"]["name"];
$attach_size = $_FILES["attach"]["size"];
$attach_type = $_FILES["attach"]["type"];
// altere para seus dados
//email da associação
$remetente="ASSCRG <[email protected]>";
//$mailheaders = "Content-Type: text/html; charset=iso-8859-1\n";
$mailheaders.="From: $remetente\n \r";
$mailheaders .= "Reply-To: $remetente\n";
//e define a mensagem tirando barras para evitar problemas no script
$body = "Mensagem: " . $_POST["mensagem"] . "\n";
$msg_body = stripslashes($body);
//verifica se tem imagem no anexo, o if é se tiver e o else se não tiver anexo
if ($attach !=null)
{
//abre a imagem para codificá-lo no formato de email
$file = fopen($attach, "r");
$contents = fread($file, $attach_size);
$encoded_attach = chunk_split(base64_encode($contents));
fclose($file);
//define os headers do anexo e da mensagem
$mailheaders .= "MIME-version: 1.0\n";
$mailheaders .= "Content-type: multipart/mixed; ";
$mailheaders .= "boundary=\"Message-Boundary\"\n";
$mailheaders .= "Content-transfer-encoding: 7BIT\n";
$mailheaders .= "X-attachments: $attach_name";
$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/plain; charset=US-ASCII\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";
$msg_body = $body_top . $msg_body;
$msg_body .= "\n\n--Message-Boundary\n";
$msg_body .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_body .= "Content-Transfer-Encoding: BASE64\n";
$msg_body .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
$msg_body .= "$encoded_attach\n";
$msg_body .= "--Message-Boundary--\n";
//envia o email para as variáveis já definidas
// enquanto tiver dados no banco, atribui o valor do campo email à variával $mail, e envia o email
mail($email, stripslashes($assunto), $msg_body, $mailheaders);
}
else{
//se não tiver anexo ele envia só a mensagem com esses headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: <$remetente>\r\n";
// enquanto tiver dados no banco, atribui o valor do campo email à variával $mail, e envia o email
mail($email, stripslashes($assunto), $msg_body, $mailheaders);
}
?>