0

I am trying to add a contact in Exchange, using the php-ews and the following code:

$request = new EWSType_CreateItemType();

$request->SendMeetingInvitations = 'SendToNone';

$contact = new EWSType_ContactItemType();
$contact->GivenName = $updates['name'];
$contact->Surname = $updates['surname'];

if($updates['email'] != ""){
    $email = new EWSType_EmailAddressDictionaryEntryType();
    $email->Key = new EWSType_EmailAddressKeyType();
    $email->Key->_ = EWSType_EmailAddressKeyType::EMAIL_ADDRESS_1;
    $email->_ = $updates['email'];

    // set the email
    $contact->EmailAddresses = new EWSType_EmailAddressDictionaryType();
    $contact->EmailAddresses->Entry[] = $email;
}

$contact->CompanyName = $updates['companyname'];

$contact->JobTitle = $updates['jobtitle'];

$contact->Birthday = $updates['birthday'];

$request->Items->Contact[] = $contact;

$response = $this->ews->CreateItem($request);

Where $updates is an array of strings I have as a parameter. (I skipped the includes, tell me if you need them.)

Now, the contact gets created and everything works, but the birthday event does not get created automatically in my calendar.

So, I would like to know if there's a simple way to have this done, except the obvious (non-elegant) way of creating it manually.

Thank you in advance, Riccardo

Guerriky
  • 529
  • 1
  • 5
  • 15
  • Can you provide a sample 'birthday' string? It may be a format issue. – ThomasEllis Jul 24 '14 at 20:08
  • I'm pretty sure it's not a format issue, as the 'birthday' field is correctly syncronized, it's the corresponding event that doesn't get automathically created (as when you set the birtday manually in Outlook). Forgot to mention that in the question. My bad. – Guerriky Jul 24 '14 at 21:24

1 Answers1

0

Could solve this using DateTime in the right format as expected in the comments.

$contact->Birthday = (new DateTime($updates['birthday']))->format(DATE_W3C);

https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/time-zones-and-ews-in-exchange

The time zone specified in the value of dateTime elements can take three forms. You can read all the details in XML Schema Part 2: Datatypes Second Edition, but to paraphrase:

  • Universal Coordinated Time (UTC): Specified by 'Z'. For example, 2014-06-06T19:00:00.000Z
  • Specific time zone: Specified by '+' or '-' followed by hours and minutes. For example, 2014-06-06T19:00:00.000-08:00
  • No time zone: Specified by the absence of any time zone. For example, 2014-06-06T19:00:00.000
Community
  • 1
  • 1
ptcooo
  • 1