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

如何在使用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
    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

    点赞 评论

相关推荐