Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $server="webmail.xxxxx.it:143";
- $username="utente@xxxxx.it";
- $password="*********";
- $content = file_get_contents("template.eml");
- print_r($content);
- echo '<hr>';
- if($inbox=imap_open("{"."$server/imap/novalidate-cert"."}", $username, $password)){
- $messaggi_totali=imap_num_msg($inbox);
- echo "<b>Totale messaggi:</b> $messaggi_totali<br/><br/>";
- $headers=imap_header($inbox, 214);
- $mittente= $headers->fromaddress;
- $oggetto=$headers->subject;
- $to_address=$headers->toaddress;
- $to_cc = $headers->ccaddress;
- $data=date("j/n/Y G:i:s",strtotime($headers->date));
- echo "<b>Mittente:</b> $mittente<br/>";
- echo "<b>Oggetto:</b> $oggetto<br/>";
- echo "<b>inviato a</b> $to_address <br/>";
- echo "<b>Data:</b> $data<br/><br/>";
- echo '<hr>';
- //$eml .= imap_body($inbox, 214, "FT_PEEK")."\n";
- $body = imap_body($inbox, 214)."\n";
- $messageID = imap_bodystruct($inbox, 214, "message_id");
- $content = str_replace("TEMPLATE_FROM_ADDRESS", $mittente, $content);
- $content = str_replace("TEMPLATE_TO_ADDRESS", $to_address, $content);
- $content = str_replace("TEMPLATE_TO_CC", $to_cc, $content);
- //$content = str_replace("TEMPLATE_TO_BCC", $to_bcc, $content);
- $content = str_replace("TEMPLATE_SUBJECT", $oggetto, $content);
- $content = str_replace("TEMPLATE_BODY", $body, $content);
- // Also don't forget to base64_encode the attachment content;
- $content = str_replace("TEMPLATE_ATTACH_CONTENT", base64_encode($body), $content);
- $eml = $content;
- echo $eml;
- $file = rand(1111, 9999).".eml";
- if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
- if (!fwrite($file_handle, $eml)) { echo "Cannot write to file"; }
- echo "<h4>You have successfully written data to $file</h4>";
- fclose($file_handle);
- imap_close($inbox);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement