how to send mail using outlook and php?

0

I created a small C# console app to send mails using outlook which is very simple

Outlook.Application oApp = new Outlook.Application();
            //Create the new message by using the simplest approach.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMsg.Recipients.Add("xxx@xxx.com");  //////////////////problem line 
            oMsg.Subject = "aaaa";
            oMsg.Body = "body";
            //Send the message.
            oMsg.Save();
            oMsg.Send();

This code needs to be invoked from php code .

1) It works in console just fine .

2) when i invoke from php i get a error . I noticed that this console app when called from php would run in system user. so i made outlook to run as system but i still get this error. i am running Apache server .

System.Runtime.InteropServices.COMException (0x80004004): Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) at Microsoft.Office.Interop.Outlook._MailItem.get_Recipients() at SyncEmail.Program.sendMailUsingOutlook(String recipient, String body, String subject) in D:\NotEncrypted\Projects\SyncEmail\SyncEmail\Program.cs:line 121

I am pulling my hair out looking at different things . Any help would be appreciated. Thanks for reading my post .

After i say some guys say use php i decided to go php route and wrote this code and get the same error .

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

php
outlook
asked on Stack Overflow Apr 24, 2012 by John Harris • edited Apr 25, 2012 by John Harris

2 Answers

0

PHP can get the JOB done directly

$oApp  = new COM("Outlook.Application") or die('error');
$oMsg  = $oApp ->CreateItem($oApp->OlItemTyp->olMailItem);
$oMsg ->Recipients->Add("xxx@xxx.com");
$oMsg ->Subject="aaaa";
$oMsg ->Body="body";
$oMsg ->Save();
$oMsg ->Send();
answered on Stack Overflow Apr 24, 2012 by Baba
0

Create from your C# outlook project an server, and listen to port (ex 3455) And use CURL in your php script to connect to your server(C# program)

answered on Stack Overflow Apr 24, 2012 by elo

User contributions licensed under CC BY-SA 3.0