if (!defined(‘olMailItem’)) define(“olMailItem”,0);
$objApp = new COM(“Outlook.Application”);
$myItem = $objApp->CreateItem(olMailItem);
$myItem->To=’xxxx@xxx.com’;
$myItem->SentOnBehalfOfName = ‘yyy@xxyyx.com’;
$myItem->Subject=”This is a test”;
$myItem->Body=”This is a Body Section now…..!”;
$myItem->Send();
我收到此错误
致命错误:第11251行中的D:\ NotEncrypted \ xampp \ htdocs \ copper \ system \ modules \ projects \ index.php中的消息'未捕获异常'com_exception'(!)com_exception:错误[0x80004004]操作已中止第11251行的D:\ NotEncrypted \ xampp \ htdocs \ copper \ system \ modules \ projects \ index.php
感谢您的评论和帮助..
答案 0 :(得分:0)
很可能您的Outlook组件服务未运行
运行
Start -> run -> dcomcnfg.exe
看看它是否在那里
如果MAPI.Session
可用,您还需要检查Windows注册表
Start -> Run -> HKEY_CLASSES_ROOT -> Outlook.Application -> MAPI.Session
如果找不到,请使用本教程
http://www.digiways.com/articles/php/outlook/
示例
set_time_limit(10);
if (! defined ( "olMailItem" ))
{
define ("olMailItem", 0 );
}
try {
$objApp = new COM ( "Outlook.Application" ) or die ( "Cannot Load Outlook.Application" );
$namespace = $objApp->GetNamespace("MAPI"); // or MAPI.Session
$namespace->Logon();
$myItem = $objApp->CreateItem ( olMailItem );
$myItem->To = "xxxx@xxx.com";
$myItem->SentOnBehalfOfName = "yyy@xxyyx.com";
$myItem->Subject = "This is a test";
$myItem->Body = "This is a Body Section now…..!";
$myItem->Send ();
} catch ( Exception $e ) {
var_dump ( $e->getMessage () );
debug_print_backtrace ();
}
我希望它有所帮助
答案 1 :(得分:0)
我刚从此页面找到了另一种解决方案:http://forums.devshed.com/php-development-5/php-com-automating-outlook-46167.html
基本上PHP没有像olMailList
那样的常量,所以你必须通过值来引用它。因此,要使当前脚本工作更改此行:
$myItem = $objApp->CreateItem(olMailItem);
为:
$myItem = $objApp->CreateItem(0);
这对我的情况很有用。