PHP CODE -:
<?php
$user = "[email protected]";
$script = "C:\\inetpub\\wwwroot\\shell_script\\sc.ps1";
$query = shell_exec("powershell -command $script <nul");
if($query)
{
echo "Successful" ;
}
else
echo "Failed";
}
?>
POWERSHELL CODE -:
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "[email protected]"
$Mail.Subject = "New Leave Request"
$Mail.Body ="
Dear,
This email contains the body of Email"
$Mail.Send()
I have Powershell installed on my laptop with Windows Server 2012 on Windows 8.
I have a website hosted on Windows Server 2012 IIS
When i run the powershell script sc.ps1 on command line on server by command ./sc.ps1 the mail is sent to Outlook.
But when i run the php page in which i have the shell_exec command the mail is not triggered to the outlook and returns page with message Successful as written in PHP Code. All the work is done on Windows Server 2012
Running powershell script on command line sends mail but when running script via powershell doesn't trigger the mail and returns successful only as the shell-exec query is running.
I have done set-ExecutionPolicy as unrestricted .