dougang5088 2015-07-10 06:21
浏览 240

如何在使用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条回答 默认 最新

  • dpjs2005 2015-07-10 07:23
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退