Ir para conteúdo
Fórum Script Brasil
  • 0

Formulário chega, mas anexo não abre


Jeffer Menezes

Pergunta

O script do formulário do meu site é este (com o meu e-mail):

<?php
$myemail = "

meu_email@meusite.com

"; $thankyou = "

Obrigado, Entraremos em contato o mais rapido possivel

";

if(!$_POST)
die('Please don\'t access this file directly.');

$myemail = str_replace("
",'',$myemail);
$thankyou = str_replace("
",'',$thankyou);
$thankyoupage = str_replace("
",'',$thankyoupage);

while(list($key,$val) = each($_POST)) {
if(stristr($key,'REQUIRED')){
$key = str_replace('REQUIRED','',$key);
$fields[$key] = $val;
if($val == ''){
$missing[] = '<b>'.$key.'</b>';
}
} else {
$fields[$key] = $val;
}
}

if($fields[myemail])
$myemail = $fields[myemail];

if($fields[name]){ $name = $fields[name]; } else { $name = "Rondnelly"; }
if($fields[email]){ $email = $fields[email]; } else { $email = $myemail; }
if($fields[subject]){ $subject = $fields[subject]; } else { $subject = "Web Form"; }

$message = "The following form was sent to you from your website!\n";
$message .= "-----------------------------------------------------------\n";
$message .= "Ip: $REMOTE_ADDR\n";
$message .= "Host: ".@gethostbyaddr($REMOTE_ADDR)."\n";
$message .= "Browser: $HTTP_USER_AGENT\n";
$message .= "Referrer: $HTTP_REFERER\n\n";

foreach($fields as $k=>$v) {
if($v && !stristr($k,'REQUIRED'))
if(is_array($v))
$message .= ucfirst($k).": ".implode(', ', $v)."\n\n";
else
$message .= ucfirst($k).": $v\n\n";
}

$message .= "-----------------------------------------------------------\n";
$message .= "Powered by so-Scripts/Anexed";
$message = stripslashes($message);

$mail_boundary = "x".md5(time())."x";
$header = "From: $name <$email>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: multipart/mixed; boundary=\"{$mail_boundary}\"\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-MSMail-Priority: Normal\r\n";
$header .= "X-Mailer:rond \r\n";
$header .= "This is a multi-part message in MIME format.\r\n\r\n";
$header .= "--{$mail_boundary}\r\n";
$header .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n";
$header .= "Date: ".date®."\r\n";
$header .= "Content-Transfer-Encoding:7bit\r\n\r\n";
$header .= $message."\r\n\r\n";

if($_FILES){

if (get_magic_quotes_runtime() == 1){
set_magic_quotes_runtime(0);
}

foreach($_FILES as $key=>$value){

foreach($value as $key2 => $value2){
$$key2 = $value2;
}

if (is_uploaded_file($tmp_name)) {
$fp = fopen($tmp_name,'rb');
$read = fread($fp,$size);
fclose($fp);

$file = base64_encode($read);
$file = chunk_split($file);

$header .= "--$mail_boundary\r\n";
$header .= "Content-type: $type; name=\"$name\"\r\n";
$header .= "Content-Transfer-Encoding:base64\r\n";
$header .= "Content-Disposition: attachment1; filename=\"$name\"\r\n\r\n";
$header .= "Content-Disposition: attachment2; filename=\"$name\"\r\n\r\n";
$header .= "Content-Disposition: attachment3; filename=\"$name\"\r\n\r\n";
$header .= "Content-Disposition: attachment4; filename=\"$name\"\r\n\r\n";
$header .= "Content-Disposition: attachment5; filename=\"$name\"\r\n\r\n";
$header .= $file."\r\n\r\n";
}
}
}

$valid_email = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email);

if(!$missing && $valid_email) {
mail($myemail,$subject,'',$header);

} elseif(!$valid_email){
$thankyou = "Your email address doesnt seem to be valid - please doublecheck it.";

} else {
if(count($missing)>1){
$last = array_pop($missing);
$themissing = implode(', ',$missing).' and '.$last;
$plu = 's';
} else {
$themissing = $missing[0];
}
$thankyou = "Sorry, but you do not seem to have filled out the field$plu ".$themissing.". Please go back and fill out all the required fields!";
}
$ref = getenv("HTTP_REFERER");
if (stristr($ref,'?'))
$sep = "&";
else
$sep = "?";

$thankyou .= ' <small>Powered by Rondnelly</a>.</small>';
$thankyou = urlencode($thankyou);



header("Location: $ref${sep}message=$thankyou");

?>
[/codebox]

O formulário é o seguinte:

[code]<td align="center">             <form enctype='multipart/form-data' action='enviar_arquivo2.php' method='post' name='form2'> <input type='hidden' name='MAX_FILE_SIZE' value='200'> <table border="0" style="border-collapse: collapse" bordercolor="#000066" width="95%" cellpadding="0"> <tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Nome:</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" color="#FFFFFF"><input type=text name="nome" size=30> (Requerido)</font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">E-mail:</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" color="#FFFFFF"> <input type=text name="email" size=30> (Requerido)</font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Idade:</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" color="#FFFFFF"> <input type=text name="idade" size=30> (Requerido)</font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">RG:</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" color="#FFFFFF"><input type=text name="rg" size=30> (Requerido)</font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Telefone:</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" color="#FFFFFF"> <input type=text name="telefone" size=30> (Requerido)</font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Cidade:</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" color="#FFFFFF"> <input type=text name="cidade" size=30> (Requerido)</font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Descrição:</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" face="Verdana" color="#FFFFFF"> <textarea name="mensagem" rows=2 cols=28></textarea></font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Foto</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" face="Verdana" color="#FFFFFF"><input type='hidden' name='MAX_FILE_SIZE' value='200'> </font><font size="1" color="#FFFFFF"> <input type='file' name="attachment1"> (Requerido)</font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Foto</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" face="Verdana" color="#FFFFFF"><input type='hidden' name='MAX_FILE_SIZE' value='200'> </font><font size="1" face="Verdana" color="#FFFFFF"> <input type='file' name="attachment2"></font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Foto</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" face="Verdana" color="#FFFFFF"><input type='hidden' name='MAX_FILE_SIZE' value='200'> </font><font size="1" face="Verdana" color="#FFFFFF"> <input type='file' name="attachment3"></font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Foto</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" face="Verdana" color="#FFFFFF"><input type='hidden' name='MAX_FILE_SIZE' value='200'> </font><font size="1" face="Verdana" color="#FFFFFF"> <input type='file' name="attachment4"></font></td></tr><tr>     <td height="30" width="189" bgcolor="#000000" bordercolor="#FFFFFF"> <font face="Verdana" size="1" color="#FFFFFF">Foto</td> <td height="30" width="469" bgcolor="#000000" bordercolor="#FFFFFF" align="left"> <font face="Verdana"><font size="1" face="Verdana" color="#FFFFFF"><input type='hidden' name='MAX_FILE_SIZE' value='200'> </font><font size="1" face="Verdana" color="#FFFFFF"> <input type='file' name="attachment5"></font></td></tr><tr>     <td colspan="2" bgcolor="#000000" height="25" width="737"><p align="center">     <font size="1" color="#FFFFFF" face="Verdana"><font face="Verdana">     <input type=submit value='Enviar anúncio' style="color: #FFFFFF; border: 1px solid #FFFFFF; background-color: #CC0099"></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     <font face="Verdana">     <input type=reset value='Limpar formulário' style="color: #FFFFFF; border: 1px solid #FFFFFF; background-color: #CC0099"></font></font></td></tr> </table></form> </td>[/code]

Há algo errado?

O problema é que, as mensagens, chegam, junto com as imagems em anexo, mas as imagens ou qualquer arquivo anexado vem totalmente corrompido (não abre).

O servidor tem suporte ao envio direto de mensagens com imagens (eu já testei).

Alguém pode me dar uma força?

Editado por Jeffer Menezes
Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...