Php Symfony2使用exchange服务器发送电子邮件

Php Symfony2使用exchange服务器发送电子邮件,php,email,symfony,exchange-server,php-ews,Php,Email,Symfony,Exchange Server,Php Ews,我是Symfony的新手,我成功创建了一个简单的Symfony2.3.5应用程序,该应用程序应该通过Microsoft Exchange Server 2007发送(仅发送)自动电子邮件,我有一个用户和密码;一个普通的电子邮件用户,我可以使用这个用户在Linux中使用API for exchange发送Outlook或Evolution的电子邮件。但我不知道如何从Symfony应用程序向此服务器发送电子邮件,然后服务器应该像我的用户发送的任何普通电子邮件一样发送。有没有人曾经在MS exchan

我是Symfony的新手,我成功创建了一个简单的Symfony2.3.5应用程序,该应用程序应该通过Microsoft Exchange Server 2007发送(仅发送)自动电子邮件,我有一个用户和密码;一个普通的电子邮件用户,我可以使用这个用户在Linux中使用API for exchange发送Outlook或Evolution的电子邮件。但我不知道如何从Symfony应用程序向此服务器发送电子邮件,然后服务器应该像我的用户发送的任何普通电子邮件一样发送。有没有人曾经在MS exchange上这样做过?有没有我能读懂的文件来了解它的工作原理

我一直在阅读有关PhpEws的文章,但我不知道它是否适用于这种情况,我也不知道如何将其添加到Symfony中,我已经尝试过,但没有成功,这就是我决定询问此问题的原因。
问候并感谢你

显然,我成功地使它与Php Ews一起工作,使用我使用的方法,它可以工作,即使我知道这不是正确的方法。我已经在我的项目的Controller文件夹中包含了phpews文件夹。我已经创建了一个新的路由来响应/发送电子邮件,然后在控制器中添加了以下内容:

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);        
}
namespace Osd\RetireBundle\Controller;
使用Symfony\Component\HttpFoundation\Response;
使用PhpEws\ExchangeWebServices;
类EmailsController{
公共函数索引()
{
$this->sendmail();
返回新的响应('Hello!');
}
受保护的函数sendmail(){
$PhpEwsPath=\uuuuu DIR\uuuu.“/php ews/”;
需要_once$PhpEwsPath.'ExchangeWebServices.php';
需要_once$PhpEwsPath.NTLMSoapClient.php';
需要_once$PhpEwsPath.NTLMSoapClient/Exchange.php';
需要_once$PhpEwsPath.EWS_Exception.php';
需要_once$PhpEwsPath.EWSType.php';
需要_once$PhpEwsPath.EWSType/MessageType.php';
需要_once$PhpEwsPath.EWSType/EmailAddressType.php';
需要_once$PhpEwsPath.EWSType/BodyType.php';
需要_once$PhpEwsPath.EWSType/SingleRecipientType.php';
需要_once$PhpEwsPath.EWSType/CreateItemType.php';
需要_once$PhpEwsPath.EWSType/NonEmptyArrayOfAllItemsType.php';
需要_once$PhpEwsPath.EWSType/ItemType.php';
$server='server';
$username='username';
$password='password';
$ews=new\ExchangeWebServices($server、$username、$password);
$msg=new\EWSType\u MessageType();
$toaddress=array();
$toaddress[0]=新建\EWSType\u EmailAddressType();
$ToAddresss[0]->EmailAddress='1email@example.com';
$toaddress[0]->Name='johndoe';
/*$toaddress[1]=新建\EWSType\u EmailAddressType();
$ToAddresss[1]->EmailAddress='1email2@example.com';
$toaddress[1]->Name='Richard Roe';
$toaddress[2]=新建\EWSType\u EmailAddressType();
$toaddress[2]->EmailAddress='1email3@example.com';
$toaddress[2]->Name='Hustle and Flow';
$toaddress[3]=新建\EWSType\u EmailAddressType();
$toaddress[3]->EmailAddress='1email4@example.com';
$toaddress[3]->Name='crokedeye Moe';*/
$msg->ToRecipients=$ToAddress;
$fromAddress=new\EWSType\u EmailAddressType();
$fromAddress->EmailAddress=email@example.com';
$fromAddress->Name='Abel';
$msg->From=new\EWSType\u SingleRecipientType();
$msg->From->Mailbox=$fromAddress;
$msg->Subject='测试来自RAS的电子邮件';
$msg->Body=new\EWSType\u BodyType();
$msg->Body->BodyType='HTML';
$msg->Body->

测试来自RAS的php ews库的电子邮件; $msgRequest=new\EWSType_CreateItemType(); $msgRequest->Items=new\EWSType_nonemptyarayofallitemstype(); $msgRequest->Items->Message=$msg; $msgRequest->MessageDisposition='SendAndSaveCopy'; $msgRequest->MessageDispositionSpecified=true; $response=$ews->CreateItem($msgRequest); var_dump($response); }
}

让我告诉你。。。它起作用了!!现在我需要你的帮助来妥善组织。哪里是添加我为此创建的函数或类的正确位置。
提前谢谢你。

我不知道发生了什么事;这个问题太难、太傻、太离题了吗?我还需要澄清什么吗?我们在休假吗?我要求太多了吗?是否没有针对此问题的现有技术解决方案?有人知道吗?这真是糟糕的做法!对依赖项使用
composer
。您是否注意到一年多前有人问过它?它起作用意味着它起作用了我知道它不好。。。但到那时,我已经有足够的问题让它工作了,没有其他人给我任何线索。无论如何,谢谢你,但这项工作是用你看到的方法完成的,就像它为他们工作一样。。。生意结束了。也许对于2.0版,我会添加它。