【发布时间】:2017-04-16 08:08:17
【问题描述】:
您好需要准备 Outlook 电子邮件草稿并在 Outlook 中打开它。
我已经创建了 php 表单来运行向 powershell 提供变量,它调用 Outlook 方法并创建电子邮件。
当我执行下面的 powershell 时
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\wamp\www\bizops\prepare_email.ps1 >> C:\wamp\www\bizops\log.log
效果很好。
但是当我将上面的行放在一个批处理文件中并在 PHP 脚本中调用它时,
$mail_string="c:\WINDOWS\system32\cmd.exe /c START C:\wamp\www\bizops\outlook_mail.bat";
exec($mail_string);
它给了我以下错误
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
我的 powershell 代码看起来像(引发此错误的部分)
$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"
【问题讨论】:
标签: php powershell outlook