Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde galera, queria saber se é possivel, e como fazer, um script que pegue um arquivo em determinado local no servidor e mande por email, e depois vou deletar, mas deletar é simples. Como posso fazer isso?
Obrigado!
Acho que é isso que vc. quer
<?
// destinatário do email
$to_name = "Seu Nome"; // alterar aqui
$to_email = "seuemail@email.com.br"; // alterar aqui
$to = "$to_name<$to_email>";
// remetente do email
$from_name = "Nome do Destinatario"; // alterar aqui
$from_email = "destinatario@destinatario.com.br"; // alterar aqui
$from = "$from_name<$from_email>";
//$cc = "maria@aaass.com.br"; // copia
//$bcc = "ze@aaaass.com.br"; // copia
$subject = "teste de envio com anexo";
// testando com imagem , mas pode ser outro formato , basta trocar o type
$attach = "teste.jpg";
$attach_type = "image/jpeg";
$attach_name = $attach;
/*
// Texto plano vai aqui
$body = "blah blah -- plaintext version of the message\n";
$body .= "teste em <b>texto plano</b>";// Aqui vai a mensagem formatada em HTML
$body .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
$body .= "<HTML><BODY>\n";
$body .= "blah blah -- html version of the message<br>\n";
$body .= "teste em <b>html</b>";
$mailheaders = "From: $from\n";
$mailheaders .= "Reply-To: $from\n";
$mailheaders .= "Cc: $cc\n";
$mailheaders .= "Bcc: $bcc\n";
$mailheaders .= "X-Mailer: Script para enviar arquivo atachado\n";
$msg_body = stripslashes($body);
if ($attach)$file = fopen("$attach", "rb");
$contents = fread ($file, filesize ($attach));
$encoded_attach = chunk_split(base64_encode($contents ));
fclose($file);
$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";
/*
// para texto plano
$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";// para html
// caso haja problemas , tentar com os parámetros de comentário ao lado
$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/html; charset=\"iso-8859-1\"\n"; //charset=US-ASCII\n;
$body_top .= "Content-transfer-encoding: quoted-printable\n"; //Content-transfer-encoding: 7BIT\n;
$body_top .= "\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";
}
mail($to, stripslashes($subject), $msg_body, $mailheaders);
echo "enviou !!!";
/*
text/html HTML .html RFC 2854
text/css Cascade Style Sheet (CSS) .css RFC 2318
text/javascript (obsoleto) JavaScript / ECMA Script .js RFC 4329
text/plain Texto puro .txt
text/xml XML .xml RFC 3023
text/richtext Rich Text Format (RTF) .rtf
text/rtf Rich Text Format (RTF) .rtf
application/javascript JavaScript / ECMA Script .js RFC 4329
application/octet-stream Binário (download) (diversas)
application/pdf Adobe Acrobat PDF .pdf RFC 3778
application/zip Archive ZIP .zip
application/msword Microsoft Word .doc, .dot
application/vnd.ms-excel Microsoft Excel .xls
application/vnd.ms-powerpoint Microsoft PowerPoint .ppt, .pps
application/mp4 Mídia MPEG-4 .mp4 RFC 4337
application/mpeg4-generic Mídia MPEG-4 .mpeg4 RFC 4337
image/jpeg Imagem JPEG .jpg, .jpeg
image/gif Imagem GIF .gif
image/png Imagem PNG .png
image/tiff Imagem TIFF .tif, .tiff RFC 2302
audio/mpeg Áudio MPEG .mp3 RFC 3003
video/mpeg Vídeo MPEG .mpg, .mpeg
video/quicktime Vídeo Apple QuickTime .mov
application/x-shockwave-flash Animação Flash .swf
audio/x-midi Melodia MIDI .mid, .midi
audio/x-wav Som Wave .wav
audio/x-ms-wma Windows Media Audio (WMA) .wma
application/x-gzip Arquivo compactado GNUzip .gz
application/x-excel Microsoft Excel (variante não padrão) .xls
application/x-powerpoint Microsoft PowerPoint (variante não padrão) .ppt, .pps
video/x-msvideo Microsoft Video .msv
video/avi .avi
*/
?>
Exatamente do mesmo modo que faria se fosse por um upload, recomendo utilizar o phpmailer para isto
http://phpmailer.worxware.com/?pg=tutorial
Observe o método AddAttachment para adicionar anexos ao seu e-mail, basta passar o arquivo que você quer (caminho completo até o mesmo).