دمج بروتوكول IMAP في لارافل

ImapEngine هي حزمة PHP بواسطة Steve Bauman و هي توفر واجهة برمجة تطبيقات بسيطة لإدارة صناديق البريد حتى في حالة عدم وجود دعم لـ IMAP في الـ PHP.

وهي توفر واجهة برمجة تطبيقات سهلة الاستخدام لإدارة صناديق البريد، ومتوافقة مع إصدار PHP 8.1 و اﻷعلى. لنستعرض هذا المثال:

use DirectoryTree\ImapEngine\Mailbox;
 
$mailbox = new Mailbox([
'port' => 993,
'username' => '...',
'password' => '...',
'encryption' => 'ssl',
'host' => 'imap.example.com',
]);
 
$inbox = $mailbox->folders()->inbox();
 
// Get all message UIDs in the inbox.
$messages = $inbox->messages()->get();
 
// All messages in the last 7 days with a specific subject
$messages = $inbox->messages()
->since(now()->subDays(7))
->subject('Hello World')
->get();
 
// Get all messages in the inbox with various content enabled.
$messages = $inbox->messages()
->withHeaders() // Enable fetching message headers.
->withFlags() // Enable fetching message flags.
->withBody() // Enable fetching message bodies (including attachments).
->get();
بعد استرجاع الرسائل، يمكنك التفاعل معها للحصول على عنوان الرسالة، ومرسل الرسالة، والمرفقات، و تستطيع حتى وضع علامة على الرسالة على أنها مقروءة أو نقلها (لﻷرشيف مثلا):
foreach ($message->attachments() as $attachment) {
// Get the attachment's filename.
$attachment->filename();
 
// Get the attachment's content type.
$attachment->contentType();
 
// Get the attachment's contents.
$attachment->contents();
 
// Get the attachment's extension.
$extension = $attachment->extension();
 
// Save the attachment to a local file.
$attachment->save("/path/to/save/attachment.$extension");
}
 
// Mark the message as read.
$message->markSeen();
 
// Move the message to an "Archive" folder.
$message->move('Archive');

الخصائص الرئيسية

راجع شفرة المصدر ImapEngine على GitHub للحصول على تعليمات التثبيت والأمثلة.

جميع الحقوق محفوظة © 2025 Laravel | عربي