I'm looking to use the default Windows 7 Outlook 2010 mail account to send an email.
I've tried:
oApp = new COM("Outlook.Application") or die('error');
$oMsg = $oApp ->CreateItem($oApp->OlItemType->olMailItem);
$oMsg ->Recipients->Add("xxx@xxx.com");
$oMsg ->Subject="aaaa";
$oMsg ->Body="body";
$oMsg ->Save();
$oMsg ->Send();
But I get the error:
Outlook loaded, version 14.0.0.7109
Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup
`OlItemType': Unknown name. ' in C:\xampp\htdocs\Intranet_IT_Request_Form
\comunread.php:5 Stack trace: #0 C:\xampp\htdocs\Intranet_IT_Request_Form
\comunread.php(5): unknown() #1 {main} thrown in C:\xampp\htdocs
\Intranet_IT_Request_Form\comunread.php on line 5
My research tells me I need cdo.dll, which contains all the email functions, but I can only install this with Outlook 2007; not practical at all.
Does anyone know how to send an Outlook 2010 email using PHP? (I'm using XAMPP).
Many many thanks
This works:
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();
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}\\n";
$oMsg = $outlook_Obj->CreateItem(olMailItem);
$oMsg->Recipients->Add($to);
$oMsg->Subject=$subject;
$oMsg->Body=$message;
$oMsg->Save();
$oMsg->Send();
?>
Please, ensure that you have added
[COM_DOT_NET]
extension=php_com_dotnet.dll
at the end of php.ini (In my case I have PHP 5.3)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.