项目作者: amirsanni

项目描述 :
A simple wrapper for jamesiarmes/php-ews library
高级语言: PHP
项目地址: git://github.com/amirsanni/php-ews-wrapper.git
创建时间: 2019-04-02T15:47:47Z
项目社区:https://github.com/amirsanni/php-ews-wrapper

开源协议:MIT License

下载


php-ews-wrapper

This is a library for communicating with Exchange Web Service. It provides a very simple and easy to use API,
leveraging on jamesiarmes/php-ews library.

Installation

  1. composer require amirsanni/php-ews-wrapper

Features

  • Send Email
  • Create Draft
  • Send Messages in Draft
  • Get Inbox Messages
  • Get Unread Messages
  • Change Message Read Status
  • Delete Message
  • Get Sent Items
  • Get Outbox Items
  • Get Draft Items
  • Get Contacts
  • Get Deleted Messages
  • Get Archived Messages
  • Get Messages in Favorites Folder
  • Get Junk Messages
  • Get Tasks
  • Get Conversation History
  • Get Folders List
  • Create event

How to use

Instantiate

  1. use amirsanni\phpewswrapper\PhpEwsWrapper;
  2. $ews = new PhpEwsWrapper('accessToken', 'email', 'optionalPassword', 'optionalServerAddress', 'optionalVersion');

Note:

  • Password is required if accessToken is not provided.
  • Access token is preferred because password authentication won’t work unless for on-premise installations.
  • Server address defaults to outlook.office365.com

Supported Versions: 2007, 2009, 2010, 2013, 2016. Defaults to 2016.

Send Email

  1. $ews->mail->sender_name = "John Doe";
  2. $ews->mail->subject = "Test email";
  3. $ews->mail->body = "This is a test email";
  4. $ews->mail->recipient = 'abc@example.com'; //['abc@xyz.com', 'abc@example.com']
  5. $ews->mail->recipient_name = "Amir Sanni";
  6. $ews->mail->cc = ['abc@xyz.com', 'abc@example.com']; //'abc@example.com'
  7. $ews->mail->bcc = 'abc@example.com'; //['abc@xyz.com', 'abc@example.com']
  8. $ews->mail->attach = ['file1', 'file2', 'file3']; //'file'
  9. $ews->mail->send_as_email = 'abc@xyz.com';//to send as another user, not the logged in user. Optional
  10. $ews->mail->send();

Create Draft

  1. $ews->mail->sender_name = "Foo Bar";
  2. $ews->mail->subject = "Test email";
  3. $ews->mail->body = "This is a test email";
  4. $ews->mail->recipient = 'abc@example.com'; //['abc@xyz.com', 'john.doe@example.com']
  5. $ews->mail->recipient_name = "Amir Sanni";
  6. $ews->mail->cc = ['abc@xyz.com', 'abc@example.com']; //'abc@example.com'
  7. $ews->mail->bcc = 'abc@example.com'; //['abc@xyz.com', 'abc@example.com']
  8. $ews->mail->attach = ['file1', 'file2', 'file3']; //'file'
  9. $ews->mail->send_as_email = 'abc@xyz.com';
  10. $ews->mail->save();

Get Messages

  1. $ews->mail->limit = 30;
  2. //each of the methods takes an optional page_number of type int
  3. $ews->mail->inbox();//Messages in inbox
  4. $ews->mail->sent(3);
  5. $ews->mail->draft();
  6. $ews->mail->outbox(1);
  7. $ews->mail->conversationHistory();
  8. $ews->mail->favourites();//favorites() will also work
  9. $ews->mail->junk();
  10. $ews->mail->deleted();
  11. $ews->mail->archived();

Get Contacts

  1. $ews->contacts->limit = 10;
  2. //Method takes an optional 'pageNumber' of type int
  3. $res = $ews->contacts->get();

Get Tasks

  1. $ews->tasks->limit = 10;
  2. //Method takes an optional 'pageNumber' of type int
  3. $res = $ews->tasks->get();

Send Message From Draft

  1. $ews->mail->limit = 30;
  2. $draft_items = $ews->mail->draft();
  3. if($draft_items->status === 1 && $draft_items->messages){
  4. foreach($draft_items->messages as $item){
  5. $ews->mail->send($item->message_id, $item->change_key);
  6. }
  7. }

Change Message Read Status

  1. $ews->mail->limit = 30;
  2. $items = $ews->mail->inbox();//$ews->mail->unread()
  3. if($items->status === 1 && $items->messages){
  4. foreach($items->messages as $item){
  5. $ews->mail->markAsRead($item->message_id, $item->change_key);
  6. //$ews->mail->markAsUnread($item->message_id, $item->change_key);
  7. }
  8. }

Delete Messages

  1. $ews->mail->limit = 30;
  2. $items = $ews->mail->inbox();
  3. if($items->status === 1 && $items->messages){
  4. foreach($items->messages as $item){
  5. $ews->mail->delete($item->message_id);
  6. }
  7. }

Create Calendar Event

  1. $ews->events->event_start = '2019-06-27 08:00:00';
  2. $ews->events->event_end = '2019-06-27 10:00:00';
  3. $ews->events->timezone = 'Africa/Lagos';//Any PHP Timezone
  4. $ews->events->location = 'Fabac, VI, Lagos';
  5. $ews->events->subject = 'Test';
  6. $ews->events->event_body = 'This is a test event';
  7. $ews->events->invitees = [
  8. ['name'=>'John Doe', 'email'=>'john.doe@example.com'],
  9. ['name'=>'Foo Bar', 'email'=>'foo.bar@example.com']
  10. ];
  11. $res = $ews->events->create();

Check out the examples folder for more usage information