使用php ews向多个帐户发送电子邮件

时间:2016-12-30 08:03:49

标签: php-ews

以下代码用于使用jamesiarmes/php-ews发送电子邮件  在我的申请中

 $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);

但问题是我只能添加一个电子邮件地址作为收件人,如何在ToRecipients中添加多个电子邮件地址?

2 个答案:

答案 0 :(得分:2)

我查看了php-ews documentation。您可以通过以下方式创建包含多个收件人的阵列:

$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';

然后将其添加到您的对象中:

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

试试这个,请反馈我。

答案 1 :(得分:0)

我觉得你的问题还没有解决?

以下对我有用:

$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);