barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.65k stars 459 forks source link

[Feature Request] Save email to eml file #719

Open Cowprod opened 7 months ago

Cowprod commented 7 months ago

I'm sorry if I didn't find the method ( I searched into issues and src/PhpImap/IncomingMail.php )

I wish to save an email to a .eml file ex: $email->save($emailFilePath)

before using your project I used to do something like this :

function save_eml_file($address, $folder, $mailbox_connection, $email_id, $email_number) { $email_headers = imap_fetchheader($mailbox_connection, $email_number, FT_PREFETCHTEXT); $email_body = imap_body($mailbox_connection, $email_number); $save_path = $folder;

if (!file_exists($save_path)) {
    mkdir($save_path, 0777);
}

file_put_contents("".$save_path."/".$email_id.".eml", $email_headers."\n\n".$email_body);  

}

regards