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

FORMAIL com multiplos Anexos


danymont

Pergunta

pessoal já tenho um formail que manda direitinho mas só manda 1 dos anexos.

Gostaria de receber todos os 4 anexos mas não sei como fazer.

Vasculhei a net e nada que realmente fosse bom.

Minha ultima alternativa é vocês.

Agradeceria muito!

contato.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Danyel Monteiro</title>
<style type="text/css"><!--
body {
    background-image: url(Site/Imbases/background.jpg);
    text-align: left;
}
#email .texto tr td div {
    text-align: center;
}
--></style>
</head>
<body>
<table width="200" align="center" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td colspan="4"><img alt="" src="Site/Imbases/Alto.jpg" usemap="#Map" width="859" border="0" height="55" /></td></tr>
<tr>
<td rowspan="3" width="5"><img alt="" src="Site/Imbases/borda.jpg" width="5" height="570" /></td>
<td rowspan="3" width="400" height="570"><img alt="" src="Site/contato/basecontato1.jpg" width="400" height="570" /></td>
<td width="449" background="Site/contato/basecontato2.1.jpg" height="120"><br />
</td>
<td rowspan="3" width="5"><img alt="" src="Site/Imbases/borda.jpg" width="5" height="570" /></td></tr>
<tr>
<td background="Site/contato/basecontato2.2.jpg" height="330">
<form action="envia.php" method="post" enctype="multipart/form-data" name="email" id="email" onsubmit="return checa_formulario(this)">
<table class="texto" vspace="0" width="449" align="left" border="0" bordercolor="#cccccc" cellpadding="0" cellspacing="0" height="284" hspace="0">
<tbody>
<tr>
<td width="225" align="center" height="20" valign="middle">
<div align="left">Nome:<input name="nome" id="nome" size="25" type="text" /></div></td>
<td width="215" align="center" height="30" valign="middle">
<div align="left">Email:<input name="email_from" id="email_from" size="25" type="text" /></div></td></tr>
<tr align="center" valign="middle">
<td colspan="2" height="109">
<div align="left">
<p><input name="arquivo" id="arquivo" size="40" type="file" /><input name="arquivo" id="arquivo" size="40" type="file" /><input name="arquivo" id="arquivo" size="40" type="file" /><input name="arquivo" id="arquivo" size="40" type="file" /></p></div></td></tr>
<tr align="center" valign="middle">
<td colspan="2" height="30">
<div align="left">
<p><textarea name="mensagem" cols="45" rows="5" id="mensagem"></textarea></p></div></td></tr>
<tr align="center" valign="middle">
<td colspan="2" height="24"><input name="enviar" id="enviar" value="Enviar" type="submit" /><input name="apagar" id="apagar" value="Apagar" type="reset" /></td></tr></tbody></table></form>      </td></tr>
<tr>
<td width="120" background="Site/contato/basecontato2.3.jpg"><img alt="" src="Site/contato/basecontato2.3.jpg" usemap="#Map2" width="448" border="0" height="120" /></td></tr>
<tr>
<td colspan="4"><img alt="" src="Site/Imbases/baixo.jpg" width="859" border="0" height="25" /></td></tr></tbody></table>
<map name="Map" id="Map">
<area alt="" shape="rect" coords="27,11,197,42" href="Site/fotografo/fotografo.html" />
<area alt="" shape="rect" coords="222,8,408,46" href="Site/portifolio/portifolio.html" />
<area alt="" shape="rect" coords="434,10,648,46" href="Site/testemunhos/testemunhos.html" />
<area alt="" shape="rect" coords="671,8,842,43" href="Site/produtos/produtos.html" /></map>
<map name="Map2" id="Map2">
<area alt="" shape="rect" coords="43,8,415,41" href="Site/siga/siga.html" />
<area alt="" shape="rect" coords="7,85,434,114" href="Site/contato/e-mail@email.com" /></map>
</body>
</html>
ENVIA.PHP
<?
     //pega os dados enviados pelo usuário
     $nome        = $_POST["nome"];
     $body        = "Nome: $nome
     Descrição: $mensagem";
     $to        = ""; //Coloque aqui o seu email
     $from    = $_POST["email_from"];
     $subject  = "teste de envio"; //Coloque aqui o assunto da mensagem enviada para o seu email
     $attach  = $_FILES["arquivo"]["tmp_name"];
     $attach_name  = $_FILES["arquivo"]["name"];
     $attach_size  = $_FILES["arquivo"]["size"];
     $attach_type  = $_FILES["arquivo"]["type"];
     
     $attach1  = $_FILES["arquivo1"]["tmp_name"];
     $attach_name1  = $_FILES["arquivo1"]["name"];
     $attach_size1  = $_FILES["arquivo1"]["size"];
     $attach_type1  = $_FILES["arquivo1"]["type"];
     
     $attach2  = $_FILES["arquivo2"]["tmp_name"];
     $attach_name2  = $_FILES["arquivo2"]["name"];
     $attach_size2  = $_FILES["arquivo2"]["size"];
     $attach_type2  = $_FILES["arquivo2"]["type"];
     
     $attach3  = $_FILES["arquivo3"]["tmp_name"];
     $attach_name3  = $_FILES["arquivo3"]["name"];
     $attach_size3  = $_FILES["arquivo3"]["size"];
     $attach_type3  = $_FILES["arquivo3"]["type"];
    
     //verifica se o email do remetente é válido
     if (!ereg("^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$", $from)){
    
     echo "<center>Erro: Digite um e-mail válido</center>";
     exit;
    
     }
    
     //define os headers de envio
     $mailheaders = "From: \"$nome\" <$from>\r\n";
     $mailheaders .= "Reply-To: $from\n";
     //e define a mensagem tirando barras para evitar problemas no script
     $msg_body = stripslashes($body);
    
    
     //verifica se tem arquivo anexo, o if é se tiver e o else se não tiver anexo
     if ($attach !=null)
     {
     //abre o arquivo 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 e tratadas e mostra mensagem de sucesso
     mail($to, stripslashes($subject), $msg_body, $mailheaders);
     echo"<center>Enviado com Sucesso!</center>";
     }
     else{
     //se não tiver anexo ele envia só a mensagem com esses headers
     echo "<center>Erro: Envio de ficheiro obrigatório!!!</center>";
     exit;
     $headers  = "MIME-Version: 1.0\r\n";
     $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
     $headers .= "From: \"$nome\" <$from>\r\n";
    
     mail($to, stripslashes($subject), $msg_body, $mailheaders);
     echo"<center>Enviado com Sucesso!</center>";
     }
     ?>

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

olá danymont,

eu não testei seu código, mas tente algo assim:

HTML

<input name="arquivo[]" id=arquivo" size="40" type="file" />

<input name="arquivo[]" id="arquivo" size="40" type="file" />

<input name="arquivo[]" id="arquivo" size="40" type="file" />

<input name="arquivo[]" id="arquivo" size="40" type="file" />

PHP

<?php

for($m = 0; $m < 4; $m++){

$attach = $_FILES["arquivo]["tmp_name"][$m];

$attach_name = $_FILES["arquivo"]["name"][$m];

$attach_size = $_FILES["arquivo"]["size"][$m];

$attach_type = $_FILES["arquivo"]["type"][$m];

....

//resto do seu código

....

}

esse é o caminho.... você tb pode usar o foreach() se for o caso....

abraços

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

  • 0

Testei isso, Mas ele manda 4 e-mails com 1 anexo cada.

Tem como deixar para ele mandar 4 anexos em 1 unico e-mail?

olá danymont,

eu não testei seu código, mas tente algo assim:

HTML

<input name="arquivo[]" id="arquivo" size="40" type="file" />

<input name="arquivo[]" id="arquivo" size="40" type="file" />

<input name="arquivo[]" id="arquivo" size="40" type="file" />

<input name="arquivo[]" id="arquivo" size="40" type="file" />

PHP

<?php

for($m = 0; $m < 4; $m++){

$attach = $_FILES["arquivo"]["tmp_name"][$m];

$attach_name = $_FILES["arquivo"]["name"][$m];

$attach_size = $_FILES["arquivo"]["size"][$m];

$attach_type = $_FILES["arquivo"]["type"][$m];

....

//resto do seu código

....

}

esse é o caminho.... você tb pode usar o foreach() se for o caso....

abraços

Link para o comentário
Compartilhar em outros sites

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,2k
    • Posts
      652k
×
×
  • Criar Novo...