Reputation: 2346
I am using three legged method to get email backups grom gmail inbox. Im trying to store the gmail mail object string to file for email backup, saving it as .eml file. using the following code:
<?php
for($i = $totalMessages; $i >= ($totalMessages-$pager) && $i <= $totalMessages; $i-- )
{
$msg = $storage->getMessage($i);
file_put_contents($i.".eml", $msg);
?>
I can not find necessary information in the mail when I see it in outlook or any other mail browser, niether the attachments are shown as they should appear, but the attachments are shown in base64 encoded as string.
I want to see them in mail browser as they should appear propperly, and later on restore email to inbox. can somebody help me?
Upvotes: 0
Views: 576
Reputation: 498
You have to add the headers to the .eml file in order to show it in some email client(outlook etc.)
I did it the following way:
= ($totalMessages-$pager) && $i <= $totalMessages; $i--) { $msg = $storage->getMessage($i);
$headers = "Date: " . $msg->date."\n"
."Delivered-To: ". $msg->to ."\n"
."Subject: " . $msg->subject ."\n"
."From: " . $msg->from ."\n"
."To: " . $msg->to ."\n"
."Content-Type: " . $msg->contentType."\n\n";
file_put_contents($i.".eml", $headers.$msg->getContent());
?>
Best of luck
Upvotes: 1