Autor Tópico: Formulário de UPLOAD de Imagem com envio para e-mail em PHP -SOCORRO  (Lida 1745 vezes)

Offline jorge.faleiros

  • Newbie
  • *
  • Mensagens: 1
  • Reputação: +0/-0
    • Ver Perfil
Olá pessoal, estou com os seguinte problema peguei um formulario de com upload de imagem que envia para email, fiz algumas alterações, ele funciona, envia tudo para o e-mail, porém a imagem ou documento que eu anexo dá erro e não abre. será que alguem pode me ajudar ?
<?php
if (getenv("REQUEST_METHOD") == "POST")
{

$nome     = "A LETRA CAIXA";//$email         = "comercial@iniciativainformatica.com";
$email   = "comercial@iniciativainformatica.com";
$mensagem  = "mensagem";
$corpo .= "Nome: " . $_POST["nome"] . "\n";
$telefone  = "telefone";
$assunto   = "ORCAMENTO";
$anexos = 0;
$boundary = "XYZ-" . date("dmYis") . "-ZYX";
$mens  = "--$boundary\n";       
$mens .= "Content-Transfer-Encoding: 8bits\n";
$mens .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n\n";
$mens .= "Nome: " . $_POST["nome"] . "\n";
$mens .= "
Assunto: " . $_POST["assunto"] . "\n";
$mens .= "
E-mail: " . $_POST["email"] . "\n";
$mens .= "
DDD: " . $_POST["ddd"] . "\n";
$mens .= "
Telefone: " . $_POST["telefone"] . "\n";
$mens .= "
Mensagem: " . $_POST["mensagem"] . "\n";
$mens .= "--$boundary\n";
for($i = 0; $i < count($_FILES["file"]["name"]); $i++)
{
if(is_uploaded_file($_FILES["file"]["tmp_name"][$i])){
$fp = fopen($_FILES["file"]["tmp_name"][$i], "rb");               
$anexo = chunk_split(base64_encode(fread($fp, $_FILES["file"]["size"][$i])));           
fclose($fp);
$mens .= "Content-Type: ".$_FILES["file"]["type"][$i]."\n name=\"".$_FILES["file"]["name"][$i]."\"\n";               
$mens .= "Content-Disposition: attachment; filename=\"".$_FILES["file"]["name"][$i]."\"\n";                             
$mens .= "Content-transfer-encoding:base256\n\n";               
$mens .= $anexo."\n";
if($i + 1 == count($_FILES["file"]["name"]))                       
$mens.= "--$boundary--";               
else
$mens.= "--$boundary\n";
if($_FILES["file"]['error'][$i] == 0) {
$anexos++;
 }                     
 }     
 }
$headers  = "MIME-Version: 1.0\n";
$headers .= "Date: ".date("D, d M Y H:i:s O")."\n";
$headers .= "From: \"CONTATO A LETRA CAIXA - ORCAMENTO\" <email_do_remetente>\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
if(mail($email, $assunto, $mens, $headers)){       
echo "Seu pedido de orçamento foi enviado com sucesso, com $anexos anexos ";
} else {
echo "Nao foi possivel enviar o email";
}       
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
<!--
.style2 {   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 11px;
   color: #FFFFFF;
}
.style3 {color: #666666}
body {
   margin-left: 0px;
   margin-top: 0px;
   margin-right: 0px;
   margin-bottom: 0px;
}
-->
</style>
</head>

<body>
<form action="anexo.php" method="post" enctype="multipart/form-data" id="form1">
  <div id="conteudo">
    <table width="450" height="364" border="0" align="center" cellpadding="0" cellspacing="10" >
          <tr>
            <td width="34%"><div align="right">
              <p>

               

               

               

               

              </p>
              </div></td>
            <td width="66%" class="style2"><p>&nbsp;              </p>
            </td>
          </tr>
          <tr>
            <td>Nome</td>
            <td width="66%" class="style2"><input name="nome" type="text" class="style3" id="nome7" /></td>
          </tr>
          <tr>
            <td width="34%">Assunto</td>
            <td width="66%" class="style2"><input name="assunto" type="text" class="style3" id="assunto" /></td>
          </tr>
          <tr>
            <td width="34%">E-Mail</td>
            <td width="66%" class="style2"><input name="email" type="text" class="style3" id="nome3" /></td>
          </tr>
          <tr>
            <td width="34%" height="22">Telefone</td>
          <td width="66%" class="style2"><input name="ddd" type="text" class="style3" id="nome4" size="4" />
                <input name="telefone" type="text" class="style3" id="nome5" size="19" /></td>
          </tr>
          <tr>
            <td width="34%" height="70">Mensagem</td>
            <td width="66%" class="style2"><textarea name="mensagem" cols="30" class="style3" id="nome6"></textarea></td>
          </tr>
          <tr>
            <td width="34%">Logo Tipo ou Arte Desejada. (envie o arquivo em CDR ou arquivo Zipado).</td>
          <td class="style2"><input type="file" name="file[]" />
                <span id="campos"></span>

                <p>
                  <input type="submit" name="Submit" value="Enviar" />
</p></td>
          </tr>
        </table>
  </div>
</form>
</body>
</html>