Bos pessoal !
preciso de uma grande ajuda para o meu projeto. Eu quero enviar um arquivo tipo PDF para o email mas ele não funciona
Aqui esta o codigo:
Código :
Alguem me pode ajudar nisto por favor !


Aqui esta o codigo:
Código :
<html>
<head>
<script language="javascript">
function validar(){
if (email.nome_para.value == ""){
alert("Por Favor nao deixe o nome em branco!");
email.nome.focus();
return false;
}
if (email.email.value == ""){
alert("Nao deixe o email destinatario em branco!");
email.email.focus();
return false;
}
if (email.assunto.value == ""){
alert("Nao deixe o assunto em branco!!!");
email.assunto.focus();
return false;
}
if(email.arquivo.value==""){
alert("Por favor insira o ficheiro a traduzir!");
return false;
}
}
</script>
<title>Pedido de tradução</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.email {
text-transform: lowercase;
}
.texto {
color: #000;
}
.style1 {color: #000}
</style>
</head>
<?php
if(isset($_POST['submit2'])){
//Pega os dados postados pelo formulário HTML e os coloca em variaveis
$email_from='php.php@hotmail.com'; // Substitua essa linha pelo seu e-mail@seudominio
if( PATH_SEPARATOR ==';'){ $quebra_linha="\r\n";
} elseif (PATH_SEPARATOR==':'){ $quebra_linha="\n";
} elseif ( PATH_SEPARATOR!=';' and PATH_SEPARATOR!=':' ) {echo ('Esse script não funcionará corretamente neste servidor, a função PATH_SEPARATOR não retornou o parâmetro esperado.');
}
//pego os dados enviados pelo formulário
$nome_para = $_POST["nome"];
$email = $_POST["email"];
$mensagem = $_POST["mensagem"];
$assunto = $_POST["assunto"];
//formato o campo da mensagem
$mensagem = wordwrap( $mensagem, 50, "<br>", 1);
//valido os emails
$arquivo = isset($_FILES["arquivo"]) ? $_FILES["arquivo"] : FALSE;
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("dmYis") . "-ZYX";
$mens = "--$boundary" . $quebra_linha . "";
$mens .= "Content-Transfer-Encoding: 8bits" . $quebra_linha . "";
$mens .= "Content-Type: text/html; charset=\"ISO-8859-1\"" . $quebra_linha . "" . $quebra_linha . ""; //plain
$mens .= "$mensagem" . $quebra_linha . "";
$mens .= "--$boundary" . $quebra_linha . "";
$mens .= "Content-Type: ".$arquivo["type"]."" . $quebra_linha . "";
$mens .= "Content-Disposition: attachment; filename=\"".$arquivo["name"]."\"" . $quebra_linha . "";
$mens .= "Content-Transfer-Encoding: base64" . $quebra_linha . "" . $quebra_linha . "";
$mens .= "$anexo" . $quebra_linha . "";
$mens .= "--$boundary--" . $quebra_linha . "";
$headers = "MIME-Version: 1.0" . $quebra_linha . "";
$headers .= "From: $email_from " . $quebra_linha . "";
$headers .= "Return-Path: $email_from " . $quebra_linha . "";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"" . $quebra_linha . "";
$headers .= "$boundary" . $quebra_linha . "";
//envio o email com o anexo
mail($email,$assunto,$mens,$headers, "-r".$email_from);
echo"Email enviado com Sucesso!";
}
//se nao tiver anexo
else{
$headers = "MIME-Version: 1.0" . $quebra_linha . "";
$headers .= "Content-type: text/html; charset=iso-8859-1" . $quebra_linha . "";
$headers .= "From: $email_from " . $quebra_linha . "";
$headers .= "Return-Path: $email_from " . $quebra_linha . "";
//envia o email sem anexo
mail($email,$assunto,$mensagem, $headers, "-r".$email_from);
echo"Email enviado com Sucesso!";
}
}
else{
?>
<body>
<form method="post" enctype="multipart/form-data" name="email">
<h1 align="center">Pedido de tradução</h1>
<div class="traducao">
<table width="50%" border="0" align="center">
<tr>
<td><div align="right"><span class="texto">Nome do destinatario:</span></div></td>
<td><input name="nome" type="text" id="nome_para" size="50" placeholder="Nome.."></td>
</tr>
<td><div align="right" class="texto">Email de destino</div></td>
<td><input name="email" type="text" class="email" value="php.php@hotmail.com" size="50" disabled="true">
</tr>
<tr>
<td><div align="right" class="texto">Assunto</div></td>
<td><input name="assunto" type="text" id="assunto" size="50" placeholder="Assunto.."></td>
</tr>
<tr>
<td><div align="right" class="texto">Mensagem</div></td>
<td><textarea name="mensagem" cols="40" rows="5" id="mensagem" ></textarea></td>
</tr>
<tr>
<td><div align="right" class="texto">Anexo</div></td>
<td><input name="arquivo" type="file"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" class="botao-login" onclick="return validar()" name="submit2" value="Enviar"><br><br><br><br></td>
</tr>
</table>
</div>
</form>
<?php
}
?>
</body>
</html>
<head>
<script language="javascript">
function validar(){
if (email.nome_para.value == ""){
alert("Por Favor nao deixe o nome em branco!");
email.nome.focus();
return false;
}
if (email.email.value == ""){
alert("Nao deixe o email destinatario em branco!");
email.email.focus();
return false;
}
if (email.assunto.value == ""){
alert("Nao deixe o assunto em branco!!!");
email.assunto.focus();
return false;
}
if(email.arquivo.value==""){
alert("Por favor insira o ficheiro a traduzir!");
return false;
}
}
</script>
<title>Pedido de tradução</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.email {
text-transform: lowercase;
}
.texto {
color: #000;
}
.style1 {color: #000}
</style>
</head>
<?php
if(isset($_POST['submit2'])){
//Pega os dados postados pelo formulário HTML e os coloca em variaveis
$email_from='php.php@hotmail.com'; // Substitua essa linha pelo seu e-mail@seudominio
if( PATH_SEPARATOR ==';'){ $quebra_linha="\r\n";
} elseif (PATH_SEPARATOR==':'){ $quebra_linha="\n";
} elseif ( PATH_SEPARATOR!=';' and PATH_SEPARATOR!=':' ) {echo ('Esse script não funcionará corretamente neste servidor, a função PATH_SEPARATOR não retornou o parâmetro esperado.');
}
//pego os dados enviados pelo formulário
$nome_para = $_POST["nome"];
$email = $_POST["email"];
$mensagem = $_POST["mensagem"];
$assunto = $_POST["assunto"];
//formato o campo da mensagem
$mensagem = wordwrap( $mensagem, 50, "<br>", 1);
//valido os emails
$arquivo = isset($_FILES["arquivo"]) ? $_FILES["arquivo"] : FALSE;
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("dmYis") . "-ZYX";
$mens = "--$boundary" . $quebra_linha . "";
$mens .= "Content-Transfer-Encoding: 8bits" . $quebra_linha . "";
$mens .= "Content-Type: text/html; charset=\"ISO-8859-1\"" . $quebra_linha . "" . $quebra_linha . ""; //plain
$mens .= "$mensagem" . $quebra_linha . "";
$mens .= "--$boundary" . $quebra_linha . "";
$mens .= "Content-Type: ".$arquivo["type"]."" . $quebra_linha . "";
$mens .= "Content-Disposition: attachment; filename=\"".$arquivo["name"]."\"" . $quebra_linha . "";
$mens .= "Content-Transfer-Encoding: base64" . $quebra_linha . "" . $quebra_linha . "";
$mens .= "$anexo" . $quebra_linha . "";
$mens .= "--$boundary--" . $quebra_linha . "";
$headers = "MIME-Version: 1.0" . $quebra_linha . "";
$headers .= "From: $email_from " . $quebra_linha . "";
$headers .= "Return-Path: $email_from " . $quebra_linha . "";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"" . $quebra_linha . "";
$headers .= "$boundary" . $quebra_linha . "";
//envio o email com o anexo
mail($email,$assunto,$mens,$headers, "-r".$email_from);
echo"Email enviado com Sucesso!";
}
//se nao tiver anexo
else{
$headers = "MIME-Version: 1.0" . $quebra_linha . "";
$headers .= "Content-type: text/html; charset=iso-8859-1" . $quebra_linha . "";
$headers .= "From: $email_from " . $quebra_linha . "";
$headers .= "Return-Path: $email_from " . $quebra_linha . "";
//envia o email sem anexo
mail($email,$assunto,$mensagem, $headers, "-r".$email_from);
echo"Email enviado com Sucesso!";
}
}
else{
?>
<body>
<form method="post" enctype="multipart/form-data" name="email">
<h1 align="center">Pedido de tradução</h1>
<div class="traducao">
<table width="50%" border="0" align="center">
<tr>
<td><div align="right"><span class="texto">Nome do destinatario:</span></div></td>
<td><input name="nome" type="text" id="nome_para" size="50" placeholder="Nome.."></td>
</tr>
<td><div align="right" class="texto">Email de destino</div></td>
<td><input name="email" type="text" class="email" value="php.php@hotmail.com" size="50" disabled="true">
</tr>
<tr>
<td><div align="right" class="texto">Assunto</div></td>
<td><input name="assunto" type="text" id="assunto" size="50" placeholder="Assunto.."></td>
</tr>
<tr>
<td><div align="right" class="texto">Mensagem</div></td>
<td><textarea name="mensagem" cols="40" rows="5" id="mensagem" ></textarea></td>
</tr>
<tr>
<td><div align="right" class="texto">Anexo</div></td>
<td><input name="arquivo" type="file"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" class="botao-login" onclick="return validar()" name="submit2" value="Enviar"><br><br><br><br></td>
</tr>
</table>
</div>
</form>
<?php
}
?>
</body>
</html>
Alguem me pode ajudar nisto por favor !
