@@ -345,18 +345,36 @@ Beyond just flagging, you can move or copy messages between folders, or even del
345345
346346``` php
347347// Retrieve the first message from the inbox.
348- $message = $inbox->messages()->get()-> first();
348+ $message = $inbox->messages()->first();
349349
350- // Print basic information.
351- echo 'UID: ' . $message->uid() . PHP_EOL;
352- echo 'Subject: ' . $message->subject() . PHP_EOL;
353- echo 'Date: ' . ($message->date() ? $message->date()->toDateTimeString() : 'N/A') . PHP_EOL;
350+ // Get the message UID.
351+ $message->uid();
352+
353+ // Get the message subject.
354+ $message->subject();
355+
356+ // Get the message sender.
357+ $message->from(); // Address
358+
359+ // Get the message date.
360+ $message->date(); // Carbon\Carbon
354361
355362// Check if the message has attachments and list them.
356- if ($message->hasAttachments()) {
357- foreach ($message->attachments() as $attachment) {
358- echo 'Attachment: ' . $attachment->filename() . ' (' . $attachment->contentType() . ')' . PHP_EOL;
359- }
363+ foreach ($message->attachments() as $attachment) {
364+ // Get the attachment's filename.
365+ $attachment->filename();
366+
367+ // Get the attachment's content type.
368+ $attachment->contentType();
369+
370+ // Get the attachment's contents.
371+ $attachment->contents();
372+
373+ // Get the attachment's extension.
374+ $extension = $attachment->extension();
375+
376+ // Save the attachment to a local file.
377+ $attachment->save("/path/to/save/attachment.$extension");
360378}
361379
362380// Mark the message as read.
0 commit comments