I have a custom fuction to parse incoming emails and their attachements. Of course one email may contain multiple attachement.
I have this code:
public function parseEmail() {
// read from stdin
$fd = fopen("php://stdin", "r");
$rawEmail = "";
while (!feof($fd)) {
$rawEmail .= fread($fd, 1024);
}
fclose($fd);
$parser = new Parser();
$parser->setText($rawEmail);
$email = new Email;
$email->to = $parser->getHeader('to');
$email->from = $parser->getHeader('from');
$email->subject = $parser->getHeader('subject');
$email->body_text = $parser->getMessageBody('text');
$attachments = $parser->getAttachments();
$filesystem = new Filesystem;
foreach ($attachments as $attachment) {
$filesystem->put(public_path() . '/uploads/' . $attachment->getFilename(), $attachment->getContent());
$email->attachement()->name = $attachment->getFilename();
}
$email->save();
}
Now this code can store only one attachement. But how can I update to store multiple attachements in model?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qySodO
via IFTTT
Aucun commentaire:
Enregistrer un commentaire