Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Outlook 2010 email using PHP

Tags:

php

email

outlook

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("[email protected]");
$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

like image 296
Ian Avatar asked Dec 29 '25 19:12

Ian


1 Answers

This works:

if (!defined("olMailItem")) {define("olMailItem",0);}
$oApp  = new COM("Outlook.Application") or die('error');
$oMsg = $oApp->CreateItem(olMailItem);
$oMsg->Recipients->Add("[email protected]");
$oMsg->Subject=$subject;
$oMsg->Body=$message;
$oMsg->Save();
$oMsg->Send();
like image 196
Ian Avatar answered Jan 01 '26 09:01

Ian