Apparently I managed to make it work with Php-Ews, The with the method i have used it works even if I know is not the correct way to do it. I have included the Php-Ews folder in the Controller folder of my project. I have created a new route that responds to /emails and then inside I have added this in the controller:
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);
}
}
And let me tell you what... IT WORKS!! Now I need your help to organize it properly. where is the right place to add the function or class that I create for this.
Thank you in advanced.