Outils pour utilisateurs

Outils du site


php:contact_with_php-ews

contact avec php ews

<?php
require_once 'vendor/autoload.php';

use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\FindItemType;
use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfBaseFolderIdsType;

use \jamesiarmes\PhpEws\Enumeration\DefaultShapeNamesType;
use \jamesiarmes\PhpEws\Enumeration\DistinguishedFolderIdNameType;
use \jamesiarmes\PhpEws\Enumeration\IndexBasePointType;
use \jamesiarmes\PhpEws\Enumeration\ItemQueryTraversalType;
use \jamesiarmes\PhpEws\Enumeration\ResponseClassType;

use \jamesiarmes\PhpEws\Type\ContactsViewType;
use \jamesiarmes\PhpEws\Type\DistinguishedFolderIdType;
use \jamesiarmes\PhpEws\Type\IndexedPageViewType;
use \jamesiarmes\PhpEws\Type\ItemResponseShapeType;

// Set connection information.
$host = '';
$username = '';
$password = '';
$version = Client::VERSION_2007;

$client = new Client('mail.imailhosting.fr', $_POST['user'], $_POST['pass'], $version);

// Build the request.
$request = new FindItemType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES; //<------ IMPORTANT SINNON ERREUR
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ContactsView = new ContactsViewType();

// Find contacts in the contacts folder.
$folder_id = new DistinguishedFolderIdType();
$folder_id->Id = DistinguishedFolderIdNameType::CONTACTS;
$request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;
$request->Traversal = ItemQueryTraversalType::SHALLOW;  //<------ IMPORTANT SINNON ERREUR
$response = $client->FindItem($request);

// Iterate over the results, printing any error messages or contact ids.
$response_messages = $response->ResponseMessages->FindItemResponseMessage;
foreach ($response_messages as $response_message) {
    // Make sure the request succeeded.
    if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
        $code = $response_message->ResponseCode;
        $message = $response_message->MessageText;
        fwrite(
            STDERR,
            "Failed to search for contacts with \"$code: $message\"\n"
        );
        continue;
    }

    // Iterate over the contacts that were found, printing the id of each.
    $items = $response_message->RootFolder->Items->Contact;
    foreach ($items as $item) {
        $id = $item->ItemId->Id;
      //  var_dump($item->EmailAddresses->Entry[0]->_);
      echo $item->CompleteName->FullName.'-------'.$item->EmailAddresses->Entry[0]->_;
    }
}

php/contact_with_php-ews.txt · Dernière modification: 2019/01/25 15:56 (modification externe)