Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Davicamarinha

Download anexo de email

Recommended Posts

Boa tarde,estou com uma duvida. Eu preciso criar um script aonde ele(o script), ao ser ativado, acesse o email e salve os anexos das mensagens em uma pasta no servidor. Ja consegui acessar o email e ver a quantidade de mensagens e tals, mas essa parte de copiar o anexo para a pasta é que ta pegando. Fiz esse script embaixo.

$conn = @imap_open("\{$server/imap}INBOX", $user, $pass) or die("Connection to server failed");$headers = imap_headers($conn) or die("Não existe emails!");$numEmails = sizeof($headers);echo "Você tem <b>$numEmails</b> mensagens em sua caixa de correio.<br><br>";for ($i=1; $i<$numEmails+1; $i++){$mailHeader = imap_headerinfo($conn, $i);$from = $mailHeader->fromaddress;$subject = strip_tags($mailHeader->subject);$date = $mailHeader->date;echo "Email de : $from , titulo $subject, data $date<br>";}$msgno = 1;$struct = imap_fetchstructure($conn,$msgno);$anexo = imap_fetchbody($conn, $msgno, 2);$attachment = count($struct->parts);$inlineitems = $struct->parts;//copy ($anexo,"../images/teste.jpg");if ($struct->encoding == "UTF-8"){echo imap_base64($anexo);}else{echo $anexo;}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Com esse script embaixo eu consigo ver a imagem q tem no email como anexo, mas nao consigo fazer download, alguem ajuda?

if ($download == "1") {   	$strFileName = $att[$file]->parameters[0]->value;   	$strFileType = strrev(substr(strrev($strFileName),0,4));   	$fileContent = imap_fetchbody($conn,$msgno,$file+2);   	downloadFile($strFileType,$strFileName,$fileContent);   }      function downloadFile($strFileType,$strFileName,$fileContent) {   	$ContentType = "application/octet-stream";      	if ($strFileType == ".asf")    		$ContentType = "video/x-ms-asf";   	if ($strFileType == ".avi")   		$ContentType = "video/avi";   	if ($strFileType == ".doc")   		$ContentType = "application/msword";   	if ($strFileType == ".zip")   		$ContentType = "application/zip";   	if ($strFileType == ".xls")   		$ContentType = "application/vnd.ms-excel";   	if ($strFileType == ".gif")   		$ContentType = "image/gif";   	if ($strFileType == ".jpg" || $strFileType == "jpeg")   		$ContentType = "image/jpeg";   	if ($strFileType == ".wav")   		$ContentType = "audio/wav";   	if ($strFileType == ".mp3")   		$ContentType = "audio/mpeg3";   	if ($strFileType == ".mpg" || $strFileType == "mpeg")   		$ContentType = "video/mpeg";   	if ($strFileType == ".rtf")   		$ContentType = "application/rtf";   	if ($strFileType == ".htm" || $strFileType == "html")   		$ContentType = "text/html";   	if ($strFileType == ".xml")    		$ContentType = "text/xml";   	if ($strFileType == ".xsl")    		$ContentType = "text/xsl";   	if ($strFileType == ".css")    		$ContentType = "text/css";   	if ($strFileType == ".php")    		$ContentType = "text/php";   	if ($strFileType == ".asp")    		$ContentType = "text/asp";   	if ($strFileType == ".pdf")   		$ContentType = "application/pdf";   	header ("Content-Type: $ContentType"); 	header ("Content-Disposition: attachment; filename=$strFileName; size=$fileSize;"); 		if (substr($ContentType,0,4) == "text") {	echo imap_qprint($fileContent);	} else {	echo imap_base64($fileContent);	}    }

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.