dongqiongjiong4740 2016-05-10 11:55 采纳率: 0%
浏览 43

Str替换PHP中的oft文件

I have created an OFT file (Outlook template file) using the COM plugin through PHP. What I need to do is replace the URLs with dynamic URLs on the fly when a user downloads the files. I have opened the file in a text editor and using the code below and both register errors (using the code below Outlook simply wouldn't open "Unable to open outlook")):

<?php
$file = file_get_contents('email1.oft');
file_put_contents('email1.oft',str_replace('There is a new','hello world',$file));
echo 'Completed';
?>

So my question is (how) can one read an OFT file and do a str replace on it? And if so how?

  • 写回答

1条回答 默认 最新

  • douyang2530 2016-05-10 22:49
    关注

    OFT is the same format as MSG (its format is documented), just the class id is different. It is an IStorage, and Windows storage API (StgOpenStorage etc.) can be used.

    You can also Redemption, which can open and modify standalone MSG/OFT files (it requires the MAPI system to be installed, which means you need to have Outlook installed):

      set Session = CreateObject("Redemption.RDOSession")
      set Msg = Session.GetMessageFromMsgFile("c:\Temp\OldFile.oft")
      Msg.Body = Replace(Msg.Body, "oldf", "new")
      Msg.SaveAs "c:\Temp\NewFile.oft", 2 'olTemplate
    
    评论

报告相同问题?