i am developing a site in which users can mail tickets and attach any type of files to a specific mail id. I need to add the mail subject, content and attachment to the data
In case if you want to download attachments as zip
$zip = new ZipArchive();
$tmp_file = tempnam('.', '');
$zip->open($tmp_file, ZipArchive::CREATE);
$mailbox = $connection->getMailbox('INBOX');
foreach ($mailbox->getMessage() as $message) {
$attachments = $message->getAttachments();
foreach ($attachments as $attachment) {
$zip->addFromString($attachment->getFilename(), $attachment->getDecodedContent());
}
}
$zip->close();
# send the file to the browser as a download
header('Content-disposition: attachment; filename=download.zip');
header('Content-type: application/zip');
readfile($tmp_file);
This code uses library hosted on GitHub. Hope this is helpful.