1

以下代码用于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

4

2 回答 2

2

我查看了php-ews 文档。您可以通过这种方式创建一个包含多个收件人的数组:

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

试试这个并反馈给我。

于 2016-12-30T08:07:12.783 回答
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);
于 2021-02-03T11:29:59.117 回答