【发布时间】:2015-07-27 14:36:42
【问题描述】:
PHP 代码 -:
<?php
$user = "email@outlook.com";
$script = "C:\\inetpub\\wwwroot\\shell_script\\sc.ps1";
$query = shell_exec("powershell -command $script <nul");
if($query)
{
echo "Successful" ;
}
else
echo "Failed";
}
?>
POWERSHELL 代码 -:
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "email2@outlook.com"
$Mail.Subject = "New Leave Request"
$Mail.Body ="
Dear,
This email contains the body of Email"
$Mail.Send()
我在装有 Windows Server 2012 和 Windows 8 的笔记本电脑上安装了 Powershell。
我有一个托管在 Windows Server 2012 IIS 上的网站
当我通过命令 ./sc.ps1 在服务器的命令行上运行 powershell 脚本 sc.ps1 时,邮件将发送到 Outlook。
但是,当我运行具有 shell_exec 命令的 php 页面时,邮件不会触发到 Outlook 并返回带有成功消息的页面,如 PHP 代码中所写。 所有工作都在 Windows Server 2012 上完成
在命令行上运行 powershell 脚本会发送邮件,但是当通过 powershell 运行脚本时不会触发邮件并且仅在 shell-exec 查询运行时返回成功。
我已将 set-ExecutionPolicy 设置为不受限制。
【问题讨论】:
标签: php powershell iis outlook fastcgi