2016-12-30 106 views
1

下面的代碼被用於我的應用程序使用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多個電子郵件地址?

回答

2

我檢出了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; 

試試這個,我的反饋請。

+0

親愛的安迪,我嘗試了你提到的問題,仍然沒有解決問題 –

+0

謝謝安迪,它解決了我的問題 –

+0

很高興聽到這個,有趣的編碼! :) – Andy