Hi have requirement to prepare outlook email draft and open it in Outlook.
I have created php form to run supply variables to a powershell wich invokes outlook methods and create the email.
When I execute the powershell as below
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\wamp\www\bizops\prepare_email.ps1 >> C:\wamp\www\bizops\log.log
It works perfectly.
But when I place the above line in a batch file and call it in PHP Script,
$mail_string="c:\WINDOWS\system32\cmd.exe /c START C:\wamp\www\bizops\outlook_mail.bat";
exec($mail_string);
it gives me below error
New-Object : Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following error:
80080005 Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE)).At C:\wamp\www\bizops\prepare_email.ps1:25 char:7
+ $ol = New-Object -comObject Outlook.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
my powershell code looks like (Section which thorows this error)
$ol = New-Object -comObject Outlook.Application
$ns = $ol.GetNameSpace("MAPI")
$Mail = $ol.CreateItem(0)
$Mail.Recipients.Add($mail_to_list)
$mail.Subject = $mail_subject
$mail.DeferredDeliveryTime = $deliverAt
$Mail.HTMLBody = "SOME HTML TEXT"