如何在使用Powershell脚本发送到Outlook的电子邮件中插入有效的HTML按钮
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)

$Mail.To = "email1"
$Mail.Recipients.Add("email2)
$Mail.Subject = "New Request"
$Mail.HTMLBody = " <input type='button' name='approve' value='Submit'/> &nbsp;&nbsp;&nbsp;&nbsp <input type='button' name='reject' value='Submit'/> <br/>"
$Mail.HTMLBody += "Kindly approve/reject the request

$Mail.Send()

By this script i am not able to display buttons in outlook email properly. But when opened in internet explorer button works fine.

I would also like to know after getting the button how to make it work such that clicking it send the value in the name to database

I want that when i click any of these buttons a Php runs and and column of a table in the database gets updated on clicking the button. What and where should i write the php and database[sql or oracle] script in the above code

Basically i want to have a approve/reject button for a request in email generated by Powershell and the response is then sent to database.

Php code that adds data in my db:

   <?php

          if(isset($_POST['submit']))
           {
             $connection = @oci_connect("username","password","db_name");
             $badge= $_POST['BADGE'];
             $_SESSION["badge"]=$badge;
             $reason = $_POST['REASON'];
             $dateFrom = $_POST['DATEFROM'];
             $dateTo = $_POST['DATETO'];
             $dd = $_POST['DD'];
             $backup = $_POST['BACKUP'];
             $employeeName = $_POST['EMPLOYEENAME'];
             $daterequested = date("Y/m/d");

             $_SESSION['datefrom'] = $dateFrom;
             $_SESSION['dateto'] = $dateTo;

             $main_query=oci_parse($connection,"INSERT INTO LEAVEINFO(BADGE,EMPLOYEENAME,TOL,DATEFROM,DATETO,DATEREQUESTED,STATUS,COMMENT1,BACKUP,REASON,LEAD) VALUES('$badge','$employeeName','$dd','$dateFrom','$dateTo','$daterequested','pending','','$backup','$reason','pending')");
                                                                      oci_execute($main_query,OCI_COMMIT_ON_SUCCESS);

?>

1个回答

Try the following code:

$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)

$Mail.To = "Example1@address.com"
$Mail.Recipients.Add("Example2@address.com")
$Mail.Subject = "New Request"

$linkSubmit = "http://www.example.com/"
$linkReject = "http://www.example2.com/"

$html = @"
<table cellspacing="0" cellpadding="0"> 
    <tr> 
    <td align="center" width="100" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">
        <a href="$linkSubmit" style="font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none; line-height:40px; width:100%; display:inline-block"><span style="color: #FFFFFF">Submit</span></a>
    </td> 
    </tr> 
</table> 
<br/>
<table cellspacing="0" cellpadding="0"> 
<tr> 
    <td align="center" width="100" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">
        <a href="$linkReject" style="font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none; line-height:40px; width:100%; display:inline-block"><span style="color: #FFFFFF">Reject</span></a>
    </td> 
</tr> 
</table> 
<p>Kindly approve/reject the request</p>
"@

$Mail.HTMLBody = $html
$Mail.Send()

This will give you 2 working buttons you will need to change both ($linkSubmit $linkReject) variables to your database URL.

Tip: Using the @ operator you can span your HTML string over multiple line making it easy to see what your doing.

Ref:Button CSS

dongyong6332
dongyong6332 添加了数据库插入代码。 它也适用于IE以及chrome和其他浏览器。
大约 5 年之前 回复
doufei2355
doufei2355 我添加了您要求的代码。
大约 5 年之前 回复
duanqian9503
duanqian9503 你能提供将数据添加到IE中的数据库的所有代码吗?
大约 5 年之前 回复
drzk21632
drzk21632 你还可以详细说明术语数据库URL。 其实我无法理解这一点。 我正在使用Oracle数据库和localhost上的网站。 我使用Php作为服务器端语言。
大约 5 年之前 回复
dsdxlibt98300
dsdxlibt98300 谢谢您的帮助。 你能帮我一件事吗? @Chard我希望当我单击这些按钮中的任何一个时,Php会运行,并且数据库中的表的列会在单击按钮时更新。 我应该在上面的代码中编写php和数据库[sql或oracle]脚本的内容和位置
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问