Implement Simple Mail Merge or MailMerge with Regions in Cloud Using PHP


/ Published in: PHP
Save to your folder(s)

Mail merge allows you to produce document (potentially large numbers of documents) from a single template and a structured data source. The letter may be sent out to many recipients with small changes, such as a change of address or a change in the greeting line. It can also be used to generate business reports, purchase orders, receipts, catalogs, inventories, and invoices etc.



Aspose.Words for Cloud Mail Merge allows you to generate documents from a template and XML in any language including .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more. You can use it with any language or platform that supports REST. (Almost all platforms and languages support REST and provide native REST clients to work with REST API).



This post covers mail merge in PHP, you can check Aspose.Words for Cloud documentation for other languages.


http://www.aspose.com/docs/display/wordscloud/Working+with+Mail+Merge


Copy this code and paste it in your HTML
  1. Mail Merge using PHP REST
  2.  
  3.  
  4.  
  5. /**** Section 1 ****/
  6.  
  7. // Build URI to execute mail merge
  8. $strURI = 'http://api.aspose.com/v1.1/words/Sample.docx/executeMailMerge?withRegions=true&mailMergeDataFile=Data.xml';
  9. // Use the following URI if you want to remove EmptyParagraphs,UnusedRegions,UnusedFields and ContainingFields during mail merge
  10. // $strURI = 'http://api.aspose.com/v1.1/words/Sample.docx/executeMailMerge?mailMergeDataFile=Data.xml&cleanup=EmptyParagraphs,UnusedRegions,UnusedFields,ContainingFields';
  11. /**** End Section 1 ****/
  12.  
  13. /**** Section 2 ****/
  14. $appSID = "77****-****-****-****-80*********";
  15. $appKey = "****************";
  16.  
  17. // Sign URI
  18. $signedURI = Sign($strURI, $appSID, $appKey);
  19. /**** End Section 2 ****/
  20.  
  21. /**** Section 3 ****/
  22. $responseStream = ProcessCommand($signedURI, "POST", "", "");
  23. /**** End Section 3 ****/
  24.  
  25. /**** Section 4 ****/
  26. $json = json_decode($responseStream);
  27. //build URI to download output DOC
  28. $outputFileName = $json->Document->FileName;
  29. /**** End Section 4 ****/
  30.  
  31.  
  32.  
  33.  
  34. Mail Merge using PHP SDK
  35.  
  36.  
  37.  
  38. /**** Section 1 ****/
  39.  
  40. // Specify product URI Product::$baseProductUri = "http://api.aspose.com/v1.1"; //sepcify App SID AsposeApp::$appSID = "xxxxxxxxxxxxxxxxxxxxxxxx"; //sepcify App Key AsposeApp::$appKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
  41.  
  42. /**** End Section 1 ****/
  43.  
  44. try{
  45.  
  46. /**** Section 2 ****/
  47. AsposeApp::$outPutLocation = getcwd() . "/Output/"; $mainDocumentFile = getcwd() . "/Input/SimpleMerge.doc"; $mainDocument = basename($mainDocumentFile); $xml = simplexml_load_file(getcwd() . "/Input/SimpleMerge.xml");
  48. /**** End Section 2 ****/
  49.  
  50. /**** Section 3 ****/
  51. //upload main document echo "Uploading main document...<br />"; $folder = new Folder(); $folder->uploadFile($mainDocumentFile, ""); echo "Main document uploaded <br />";
  52. /**** End Section 3 ****/
  53.  
  54. /**** Section 4 ****/
  55. echo "Executing mail merge... <br />"; //create MailMerge object $doc = new MailMerge(); $result = $doc->executeMailMerge($mainDocument, $xml->asXML());
  56. /**** End Section 4 ****/ }
  57.  
  58. catch (Exception $e)
  59. {
  60. throw new Exception($e->getMessage());
  61. }

URL: http://www.aspose.com/blogs/aspose-products/aspose-words-product-family/archive/2014/02/03/execute-mail-merge-in-php.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.