使用PHP EWS发送电子邮件到多个账户
问题描述:
下面的代码被用于我的应用程序使用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 = "[email protected]";
$response = $this->app['ews']->CreateItem($request);
发送使用jamesiarmes/php-ews
电子邮件,但问题是我只能添加一个电子邮件地址作为收件人,我怎么可以添加ToRecipients
多个电子邮件地址?
答
我检出了php-ews documentation。您可以创建多个收件人的数组是这样的:
$toAddresses = array();
$toAddresses[0] = new EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress = '[email protected]';
$toAddresses[0]->Name = 'John Harris';
$toAddresses[1] = new EWSType_EmailAddressType();
$toAddresses[1]->EmailAddress = '[email protected]';
$toAddresses[1]->Name = 'Sara Smith';
然后将其添加到你的对象是这样的:
$request->Items->Message->ToRecipients = $toAddresses;
试试这个,我的反馈请。
亲爱的安迪,我尝试了你提到的问题,仍然没有解决问题 –
谢谢安迪,它解决了我的问题 –
很高兴听到这个,有趣的编码! :) – Andy