-1

How can I send email by Outlook software installed on client systems by PHP?

Can I use PHPMailer and set host to local Outlook software? Or should I use JavaScript to send email, when Outlook opened on system?

I used this PHP code and return error:

if (!defined("olMailItem")) {define("olMailItem",0);}
$oApp  = new COM("Outlook.Application") or die('error');
$oMsg = $oApp->CreateItem(olMailItem);
$oMsg->Recipients->Add("mk.kardgar@gmail.com");
$oMsg->Subject=$subject;
$oMsg->Body=$message;
$oMsg->Save();
$oMsg->Send();

error:

Fatal error: Uncaught com_exception: Failed to create COM object Outlook.Application': Invalid syntax in C:\projects\ccs\modules\callReview\admin\just\cancellation\ajax\sendEmailCancellation.php:15 Stack trace: #0 C:\projects\ccs\modules\callReview\admin\just\cancellation\ajax\sendEmailCancellation.php(15): com->com('Outlook.Applica...') #1 C:\projects\ccs\admin\just.php(26): include('C:\\projects\\ccs...') #2
halfer
  • 19,471
  • 17
  • 87
  • 173

1 Answers1

0

For the COM error, you can refer to the following links:

Fatal error: Uncaught exception 'com_exception'

PHP COM problem

Have you checked your Outlook app is running?

Also, if you want to send email by JS, please see How to send an email from JavaScript

Simon Li
  • 303
  • 2
  • 4