Enviar como anexo Arquivos Que Estão Numa Pasta
pessoal, passei o final de semana tentando resolver isso e consegui avançar um pouco, mas agora não sei mais como posso resolver...o código abaixo está funcionando perfeitamente para o envio de 1 arquivo, mas preciso de ajuda para enviar vários que estarão dentro de uma pasta no servidor.
$para = "$email\r\n";$mensagem = ('<html>mensagem</html>');$assunto = $subject;$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 .= "$mensagem\n";$mens .= "--$boundary\n";if ($anex == '1'){$dir = 'files/';if (is_dir($dir)) {if ($dh = opendir($dir)) {while (($file = readdir($dh)) !== false) {if(($file!= '.') and ($file!= '..')) { $mens .= "Content-Type: " . filetype($dir . $file) . "\n name=\"".$file."\"\n";$mens .= "Content-Disposition: attachment; filename=\"".$file."\"\n"; $mens .= "Content-transfer-encoding:base64\n\n"; $mens .= $anexo."\n";if($file !== false) { $mens.= "--$boundary--"; }else {$mens.= "--$boundary\n"; } } } closedir($dh);}}}$headers = "MIME-Version: 1.0\n";$headers .= "Date: ".date("D, d M Y H:i:s O")."\n";$headers .= "From: $emailll\r\n";$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";mail($para, $assunto, $mens, $headers);
tentei utilizar o for como segue, mas não deu certo.Desta forma, se eu anexar 2 arquivos, vai 1 só, sendo o nome de 1 e o conteudo do outro.
if ($anex == '1'){$dir = 'files/';if (is_dir($dir)) {if ($dh = opendir($dir)) {$cont=count($dh);for($j=0;$j<=$cont;$j++){while (($file[$j] = readdir($dh)) !== false) {if(($file[$j]!= '.') and ($file[$j]!= '..')) { $mens .= "Content-Type: " . filetype($dir . $file[$j]) . "\n name=\"".$file[$j]."\"\n";$mens .= "Content-Disposition: attachment; filename=\"".$file[$j]."\"\n"; $mens .= "Content-transfer-encoding:base64\n\n"; $mens .= $anexo."\n";if($file[$j] !== false) { $mens.= "--$boundary--"; }else {$mens.= "--$boundary\n"; } $anexos++;} } } closedir($dh);}}}
desde já, muito obrigada. http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif abraço,dammy
Discussão (3)
Carregando comentários...