从php发送邮件使用Outlook 2010

I'm trying to send a Mail via the installed Outlook 2010 Client from my PHP application So far I've tried this suggestion, the top rated answer didn't work for me. Then I added

[COM_DOT_NET]
extension=php_com_dotnet.dll

at the end of php.ini (C:/xampp/php).

I also checked my registry for EnableDCOM, it is set to 'Y'.

This is the code I'm using:

<?php
if (!defined("olMailItem")) {define("olMailItem",0);}
$oApp  = new COM("Outlook.Application") or die('error');
$oMsg = $oApp->CreateItem(olMailItem);
$oMsg->Recipients->Add("xxx@xxx.org");
$oMsg->Subject=$subject;
$oMsg->Body=$message;
$oMsg->Save();
$oMsg->Send();
?>

The full error msg:

Warning: Uncaught exception 'com_exception' with message 'Failed to create COM object `Outlook.Application': Aufruf wurde durch Aufgerufenen abgelehnt. ' in C:\projekt_dreiskaen\mailtest.php:3 Stack trace: #0 C:\projekt_dreiskaen\mailtest.php(3): com->com('Outlook.Applica...') #1 {main} thrown in C:\projekt_dreiskaen\mailtest.php on line 3

Fatal error: Maximum execution time of 30 seconds exceeded in...

I'm on Win 7 Enterprise in a large corporate Windows Domain, using my local admin rights to run xampp. About 15 users will need to send e-mails from my application.

Any help would be appreciated :)

For me the next code works just out of the box:

<?php
$subject="This is a test message";

$message="This is a Body Section now.....! :)";

$to="someaddress@somedomain.com";

// starting outlook

**com_load_typelib("outlook.application");**

if (!defined("olMailItem")) {define("olMailItem",0);}

$outlook_Obj = new COM("outlook.application") or die("Unable to start Outlook");

//just to check you are connected.

echo "Loaded MS Outlook, version {$outlook_Obj->Version}
";

$oMsg = $outlook_Obj->CreateItem(olMailItem);

$oMsg->Recipients->Add($to);

$oMsg->Subject=$subject;

$oMsg->Body=$message;

$oMsg->Save();

$oMsg->Send();

?> 

I think the error (Maximum execution time of 30 seconds exceeded...) is pretty telling - most likely Outlook is displaying the profile selection dialog and there isn't anybody who can dismiss it.

Is your code running under service (such as IIS)? Outlook cannot be used from a service.