1

The below code is used for sending email using jamesiarmes/php-ews in my application

 $request = new \jamesiarmes\PhpEws\Request\CreateItemType();
  $request->MessageDisposition = "SendOnly";
  $request->SavedItemFolderId->DistinguishedFolderId->Id = "sentitems";
  $request->Items->Message->ItemClass = "IPM.Note";
  $request->Items->Message->Subject = "exchange new mail";
  $request->Items->Message->Body->BodyType = 'HTML';
  $request->Items->Message->Body->_ = "This is a test mail as a part of exchange settings set up ";
 $request->Items->Message->ToRecipients->Mailbox->EmailAddress = "rejith.rj@pitsolutions.com";
 $response = $this->app['ews']->CreateItem($request);

But the problem is I can add only one email address as recipient, how can I add multiple email addresses in ToRecipients?

webster
  • 3,902
  • 6
  • 37
  • 59
Rejith RJ
  • 43
  • 9

2 Answers2

2

I checked out the php-ews documentation. You can create an array with multiple recipients this way:

$toAddresses = array();

$toAddresses[0] = new EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress = 'john.harris@domain.com';
$toAddresses[0]->Name = 'John Harris';

$toAddresses[1] = new EWSType_EmailAddressType();
$toAddresses[1]->EmailAddress = 'sara.smith@domain.com';
$toAddresses[1]->Name = 'Sara Smith';

And then add it to your object like this:

$request->Items->Message->ToRecipients = $toAddresses;

Try this and feedback me please.

Andy
  • 393
  • 3
  • 16
0

Seems to me that your problem has not been solve yet?

Following works for me:

$toAddresses = array();
$toAddresses[0]="test@test.com";
$toAddresses[1]="test2@test.com";

$api = MailAPI::withUsernameAndPassword("server", "username", "password");

$message = new Type\MessageType();
$message->setBody('Some Text');
$message->setSubject('Test Subject');
$message->setToRecipients($toAddresses);
Daniel Bäuerlein
  • 149
  • 1
  • 1
  • 12