显然我设法使它与 Php-Ews 一起工作,即使我知道这不是正确的方法,我使用的方法也可以工作。我已将 Php-Ews 文件夹包含在我的项目的 Controller 文件夹中。我创建了一个响应 /emails 的新路由,然后在控制器中添加了它:
namespace Osd\RetireBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use PhpEws\ExchangeWebServices;
class EmailsController {
public function indexAction()
{
$this->sendEmail();
return new Response('<html><body>Hello !</body></html>');
}
protected function sendEmail(){
$PhpEwsPath = __DIR__."/php-ews/";
require_once $PhpEwsPath.'ExchangeWebServices.php';
require_once $PhpEwsPath.'NTLMSoapClient.php';
require_once $PhpEwsPath.'NTLMSoapClient/Exchange.php';
require_once $PhpEwsPath.'EWS_Exception.php';
require_once $PhpEwsPath.'EWSType.php';
require_once $PhpEwsPath.'EWSType/MessageType.php';
require_once $PhpEwsPath.'EWSType/EmailAddressType.php';
require_once $PhpEwsPath.'EWSType/BodyType.php';
require_once $PhpEwsPath.'EWSType/SingleRecipientType.php';
require_once $PhpEwsPath.'EWSType/CreateItemType.php';
require_once $PhpEwsPath.'EWSType/NonEmptyArrayOfAllItemsType.php';
require_once $PhpEwsPath.'EWSType/ItemType.php';
$server = 'server';
$username = 'username';
$password = 'password';
$ews = new \ExchangeWebServices($server, $username, $password);
$msg = new \EWSType_MessageType();
$toAddresses = array();
$toAddresses[0] = new \EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress = 'email@example.com';
$toAddresses[0]->Name = 'John Doe';
/*$toAddresses[1] = new \EWSType_EmailAddressType();
$toAddresses[1]->EmailAddress = 'email2@example.com';
$toAddresses[1]->Name = 'Richard Roe';
$toAddresses[2] = new \EWSType_EmailAddressType();
$toAddresses[2]->EmailAddress = 'email3@example.com';
$toAddresses[2]->Name = 'Hustle and Flow';
$toAddresses[3] = new \EWSType_EmailAddressType();
$toAddresses[3]->EmailAddress = 'email4@example.com';
$toAddresses[3]->Name = 'Crookedeye Moe';*/
$msg->ToRecipients = $toAddresses;
$fromAddress = new \EWSType_EmailAddressType();
$fromAddress->EmailAddress = 'email@example.com';
$fromAddress->Name = 'Abel';
$msg->From = new \EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = 'Test email message from RAS';
$msg->Body = new \EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = '<p style="font-size: 18px; font-weight: bold;">Test email message from php ews library from RAS.</p>';
$msgRequest = new \EWSType_CreateItemType();
$msgRequest->Items = new \EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $ews->CreateItem($msgRequest);
var_dump($response);
}
}
让我告诉你什么......它的工作原理!现在我需要你的帮助来妥善组织它。添加我为此创建的函数或类的正确位置在哪里。提前谢谢你。