PHPackages                             danialpanah/mail-connect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. danialpanah/mail-connect

ActiveLibrary[API Development](/categories/api)

danialpanah/mail-connect
========================

Laravel Package for Connect to Email Using IMAP

1.0.0(3y ago)017MITPHP

Since Dec 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/danialrp/laravel-mail-connect)[ Packagist](https://packagist.org/packages/danialpanah/mail-connect)[ RSS](/packages/danialpanah-mail-connect/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel Email Connect (IMAP)
============================

[](#laravel-email-connect-imap)

[![Latest Release on Packagist](https://camo.githubusercontent.com/2071e90dfe80bf0f682c7697b9d525419622db28caad2e4c66f3ab457600a88d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e69616c70616e61682f6d61696c2d636f6e6e6563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danialpanah/mail-connect)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

- [Introduction](#introduction)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Support &amp; Security](#support-security)
- [License](#license)
- [ToDo](#todo)

Introduction
------------

[](#introduction)

This Laravel package can open any Email Mailbox and access to its directories like inbox, sent items etc. Current version can only use the Imap protocol (PHP Imap), in the future releases using POP3 protocol will be added.

Installation
------------

[](#installation)

- Use following command to install:

```
composer require danialpanah/mail-connect
```

**This package supports Laravel auto-discovery feature. If you are using Laravel 6.x or greater no need to do any further actions, otherwise follow below steps to add this package manually to your application.**

- Add the service provider to your `providers[]` array in `config/app.php` in your laravel application:

```
DanialPanah\MailConnect\MailConnectServiceProvider::class
```

- For using Laravel Facade add the alias to your `aliases[]` array in `config/app.php` in your Laravel application:

```
'MailConnect': DanialPanah\MailConnect\Facades\MailConnect::class
```

Configuration
-------------

[](#configuration)

- After installation, you need to add your Email settings. You can update **config/mailconnect.php** published file or in you Laravel **.env** file.
- Run the following command to publish the configuration file:

```
php artisan vendor:publish --provider "DanialPanah\MailConnect\MailConnectServiceProvider"
```

- **config/webpay.php**

```
return [
    'email_url' => env('MAIL_CONNECT_URL', null),
    'email_username' => env('MAIL_CONNECT_USERNAME', null),
    'email_password' => env('MAIL_CONNECT_PASSWORD', null)
];
```

- Add this to `.env.example` and `.env` files:

```
#Email Connect Settings

#your Imap email url e.g "{localhost:993/imap/ssl/novalidate-cert}"
MAIL_CONNECT_URL=

#your email username (could be same as your email address or any other username) e.g "me@danialrp.com"
MAIL_CONNECT_USERNAME=

#your email password
MAIL_CONNECT_USERNAME=

```

Usage
-----

[](#usage)

Following are some examples which you can use to initiate connection to your mailbox:

- Open Imap connection and access to your mailbox contents:

```
// Importing the class namespaces before using it
use DanialPanah\MailConnect\MailConnect;

$mailConnect = new MailConnect();

$mailConnect->protocol = 'imap'; //select protocol
$mailConnect->directory = 'inbox'; //'inbox', 'sent' etc. see allowed Imap directories.
$mailConnect->criteria = 'all'; //'all', 'seen', 'unseen' etc. see allowed Imap criteria.

$messages = $mailConnect->openMailbox(); // get mailbox messages.

// Also Could be used with PHP method chaining
$messages = $mailConnect
                 ->protocol('imap')
                 ->directory('inbox')
                 ->criteria('all')
                 ->openMailbox();

```

- Using Facades :

```
use DanialPanah\MailConnect\MailConnect;

$messages = MailConnect::openMailbox();

```

- Sample Response of Verify Successful Payment:

```
array [
  0 => array:3 [
    "message_number" => 18
    "header" => array [
      "date" => "Wed, 14 Dec 2022 14:26:44 +0000"
      "subject" => "Some Subject"
      "message_id" => ""
      "toaddress" => "Danial Panah "
      "fromaddress" => "From Address "
      "reply_toaddress" => "Reply To Address "
      "senderaddress" => "Sender Address "
      "Recent" => ""
      "Unseen" => ""
      "Flagged" => ""
      "Answered" => ""
      "Deleted" => ""
      "Draft" => ""
      "Msgno" => "  18"
      "MailDate" => "14-Dec-2022 14:48:16 +0000"
      "Size" => "11566"
      "udate" => "1671029296"
    ]
    "body" => "Html Body Message"
  ]
  1 => array:3 [▶]
  2 => array:3 [▶]
  3 => array:3 [▶]
  4 => array:3 [▶]
  5 => array:3 [▶]

```

- Laravel Sample Controller:

```
