[英]how to make php Outlook.Application work and send mail?
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)中D:\\ NotEncrypted \\ xampp \\ htdocs \\ copper \\ system \\ modules \\ projects \\ index.php中消息'的未捕获异常'com_exception'消息com_exception:错误[0x80004004]操作在D:\\中中止第11251行的NotEncrypted \\ xampp \\ htdocs \\ copper \\ system \\ modules \\ projects \\ index.php
感谢您的评论和帮助。
您的Outlook组件服务很可能没有运行
跑
Start -> run -> dcomcnfg.exe
看看它是否在那里
您还需要检查Windows注册表是否MAPI.Session
可用
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 ();
}
希望对您有所帮助
我刚刚从此页面找到了另一个解决方案: http : //forums.devshed.com/php-development-5/php-com-automating-outlook-46167.html
基本上,PHP没有像olMailList
这样的常量,因此您必须通过值来引用它。 因此,要使当前脚本正常工作,请更改以下行:
$myItem = $objApp->CreateItem(olMailItem);
至:
$myItem = $objApp->CreateItem(0);
对于我的情况,这很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.