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();
i get this error
Fatal error: Uncaught exception ‘com_exception’ with message ‘ in D:\NotEncrypted\xampp\htdocs\copper\system\modules\projects\index.php on line 11251 ( ! ) com_exception: Error [0x80004004] Operation aborted in D:\NotEncrypted\xampp\htdocs\copper\system\modules\projects\index.php on line 11251
Thanks for the comments and help guys..
Most likely your Outlook Component Service is not running
run
Start -> run -> dcomcnfg.exe
To see if its there
You also need to check your windows Registry if MAPI.Session
is available
Start -> Run -> HKEY_CLASSES_ROOT -> Outlook.Application -> MAPI.Session
If you can't find this then use this tutorials
http://www.digiways.com/articles/php/outlook/
Example
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 ();
}
I hope it helps
I just found another solution from this page: http://forums.devshed.com/php-development-5/php-com-automating-outlook-46167.html
Basically PHP doesn't have the constants like olMailList
, so you have to refer to it by values. So to make your current script work change this line:
$myItem = $objApp->CreateItem(olMailItem);
to:
$myItem = $objApp->CreateItem(0);
That worked just fine for my situation.
User contributions licensed under CC BY-SA 3.0