Jump to content


Photo

Problema Em Formulario Com Anexo


  • Faça o login para participar
1 reply to this topic

#1 Aly Phoenix

Aly Phoenix

    Novato no fórum

  • Usuários
  • 14 posts
  • Sexo:Não informado

Posted 07/10/2008, 22:11

Bom pessoal, desculpe toma-los o tempo
Preciso de ajuda, peguei o seguinte formulário abaixo, pois preciso de algum que suporte anexo, mas ele dá os seguintes erros:

Notice: Undefined index: act in C:\Wamp\www\teste.php on line 51
linha 51: $act = $_GET['act'] ? $_GET['act'] : "";

e quando eu faço um teste, aperto o botão de enviar, aparece:

Notice: Use of undefined constant dmyhms - assumed 'dmyhms' in C:\Wamp\www\teste.php on line 90
Notice: Undefined variable: anexo in C:\Wamp\www\teste.php on line 103
Notice: Undefined variable: assunto in C:\Wamp\www\teste.php on line 143

90= $boundary = "XYZ-" . date(dmyhms) . "-ZYX";
103= $attachments[1] = $anexo;
143= $mensagem = mail($_POST['email'], $assunto, $message, $headers);

respectivamente;


bom, obviamente ele diz que não foi definidas as variáveis... se for esse mesmo o problema, como faço pra definir?
sou novo no assunto...


Aguardo retorno,

Muito obrigado amigos!



<body>
<form name="form1" method="post" enctype="multipart/form-data" action="<?= $_SERVER['PHP_SELF'];?>?act=enviar">
<p class="style2" style="word-spacing: 0; margin: 0">Nome</p>
<p class="style2" style="word-spacing: 0; margin: 0">
<input type="text" name="nome">
</p>
<p class="style2" style="word-spacing: 0; margin: 0">E-Mail</p>
<p class="style2" style="word-spacing: 0; margin: 0">
<input name="de" type="text" id="de">
</p>
<p class="style2" style="word-spacing: 0; margin: 0">Assunto</p>
<p class="style2" style="word-spacing: 0; margin: 0">
<input type="text" name="assunto">
</p>
<p class="style2" style="word-spacing: 0; margin: 0">Anexo</p>
<p class="style2" style="word-spacing: 0; margin: 0">
<input type="file" name="anexo"> 
O arquivo deverá ter no máximo 3Mb. </p>
<p class="style2" style="word-spacing: 0; margin: 0">Mensagem</p>
<p class="style2" style="word-spacing: 0; margin: 0">
 <textarea name="msg" cols="50" rows="10"></textarea>
</p>
<p class="style2" style="word-spacing: 0; margin: 0"></p>
<input type="hidden" value="email@seudominio.com.br" name="email">
<p class="style2" style="word-spacing: 0; margin: 0">
  <input type="submit" name="Submit" value="Enviar">
  <input name="reset" type="reset" id="reset" value="Limpar">
</p>
</form>



<?
$act = $_GET['act'] ? $_GET['act'] : "";
if ($act == "enviar"){
$mime_list = array(   "html"=>"text/html",
					 "htm"=>"text/html",
		 "txt"=>"text/plain",
		 "rtf"=>"text/enriched",
		 "csv"=>"text/tab-separated-values",
		 "css"=>"text/css",
		 "gif"=>"image/gif",
	  "doc"=>"application/msword",
	  "jpeg"=>"image/jpeg",
	  "jpg"=>"image/jpeg",
	  "jpe"=>"image/jpeg",
	  "exe"=>"application/octet-stream",
	  "mid"=>"audio/midi",
	  "midi"=>"audio/midi",
	  "mov"=>"video/quicktime",
	  "movie"=>"video/x-sgi-movie",
	  "mp3"=>"audio/mpeg",
	  "mpeg"=>"video/mpeg",
	  "mpg"=>"video/mpeg",
	  "mpga"=>"video/mpeg",
	  "png"=>"image/png",
	  "pps"=>"application/mspowerpoint",
	  "ppt"=>"application/mspowerpoint",
	  "ppz"=>"application/mspowerpoint",
	  "qt"=>"video/quicktime",
	  "ra"=>"audio/x-realaudio",
	  "rgb"=>"image/x-rgb",
	  "tif"=>"image/tiff",
	  "tiff"=>"image/tiff",
	  "wav"=>"audio/x-wav",
	  "swf"=>"application/x-shockwave-flash",
	  "zip"=>"application/zip",
	  );


$ABORT = FALSE;

$boundary = "XYZ-" . date(dmyhms) . "-ZYX";


$message = "--$boundary\n";
$message .= "Content-Transfer-Encoding: 8bits\n";
$message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n\n";
$message .= "Enviado em ". date("d/m/Y"). "<P>Confira os dados:<P>
		Nome: " .$_POST['nome']. "<BR>
		Email: " .$_POST['de']. "<BR>
		Mensagem:<BR>"
   .nl2br($_POST['msg']). "<P>";
$message .= "\n";

$attachments[1] = $anexo;

foreach ($attachments as $key => $full_path) {
if ($full_path !='') {
	 if (file_exists($full_path)){
		   if ($fp = fopen($full_path,"rb")) {
  if ((filesize($full_path)/1024) > "3000"){
				   echo "O arquivo que você tentou anexar, possui mais que 3MB. Por favor, tente um arquivo menor.";
				   exit;
}
				   $filename = array_pop(explode(chr(92),$full_path));
				   $contents = fread($fp,filesize($full_path));
				   $encoded = base64_encode($contents);
				   $encoded_split = chunk_split($encoded);
				   fclose($fp);
				   $message .= "--$boundary\n";
				   $message .= "Content-Type: $anexo_type\n";
				   $message .= "Content-Disposition: attachment; filename=\"$anexo_name\" \n";
				   $message .= "Content-Transfer-Encoding: base64\n\n";
				   $message .= "$encoded_split\n";
		   }
		   else {
		   echo "Impossível abrir o arquivo$key: $filename";
		   $ABORT = TRUE;
		   }
	 }
	 else {
	 echo "O arquivo$key não existe: $filename";
	 $ABORT = TRUE;
	 }

}
}

$message .= "--$boundary--\r\n";


$headers  = "MIME-Version: 1.0\r\n";
$headers .= "From: <".$_POST['de'].">\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\" charset=iso-8859-1\r\n";
$mensagem = mail($_POST['email'], $assunto, $message, $headers);

if ($mensagem) {
  print "Mensagem enviada com sucesso!";
} else {
  print "O envio da mensagem falhou!";
}

}

?>
</body>

Edição feita por: Aly Phoenix, 10/10/2008, 15:27.


#2 Aly Phoenix

Aly Phoenix

    Novato no fórum

  • Usuários
  • 14 posts
  • Sexo:Não informado

Posted 10/10/2008, 15:28

Up? =/




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq