Free Support Forum - aspose.com

How to do mail merge Word using Php

In This Site there is a Mail Merge Using php for Word document it is not working. for eg see my code after including your all libaries.

<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once('saaspose.php'); SaasposeApp::$AppSID = "1861f6d3-1ac4-4951-aa49-eefb3f923bb0"; SaasposeApp::$AppKey = "8f77483fd73b786c3be765b1331e920f"; SaasposeApp::$OutPutLocation = getcwd() . "\\output\\"; $mainDocumentFile = getcwd() . "\\input\\SimpleMerge.docx"; $mainDocument = basename($mainDocumentFile); $xml = simplexml_load_file(getcwd() . "\\input\\SimpleMerge.xml"); //upload main document echo "Uploading main document...
"; $folder = new Folder(); $folder->UploadFile($mainDocumentFile, ""); echo "Main document uploaded
"; echo "Executing mail merge...
"; //create WordMailMerge object $doc = new WordMailMerge(); $result = $doc->ExecuteMailMerge($mainDocument, $xml->asXML()); ?>

Submitted from: http://saaspose.com/

Hi Allen,

I was able to successfully execute this code with your AppSID and AppKey. Can you please share the error description, source document and XML?

If you are using SimpleMerge.docx from our site, you need to either upload the image 'p2' or remove image field from SimpleMerge.docx to get this code working.

Best Regards,
Muhammad Ijaz

Support Developer, Saaspose
Sialkot Team
http://www.saaspose.com

Hi,

I have Attached my full source code,with Word Doc,and Xml in that Please help how to run it

Hi Allen,

Sorry, I do not see any Word document or XML document in your shared archive. Please place attached Word document and XML inside 'input' folder, grant read/write access of 'output' folder to IIS user and run your test.php again and let us know if it works for you. Please also share exception details in case of a failure.

Best Regards,
Muhammad Ijaz

Support Developer, Saaspose
Sialkot Team
http://www.saaspose.com

Hi,

Here i have attached word document with xml

Please help me step by step process

Thanks

Allen

Hi Allen,

There were no merge fields in your document. You need to add merge fields in your document by opening the document in MS Word, selecting 'Insert' tab and then 'Quick Parts'-->'Field...'. In the Field window, select 'MergeField' from the categories list. Once merge fields are added in the document, you need to use same field names in the XML. Please also check the following topic for more details on MailMerge and MailMergeTemplate.

http://saaspose.com/docs/display/words/executeMailMerge+vs+executeTemplate
http://saaspose.com/docs/display/words/SaaSpose.Words+Templates+1.0+Features

I have also prepared a few REST and SDK examples for you. Please download attached SDK or REST examples, unzip them and open any example in browser. You just need to grant full permissions for 'Output' folder to PHP user or all users. I have used your AppSID and AppKey in the examples so you need to change nothing in the code. Input files are also included.

Please run these examples and let us know if you still find any difficulty.

Best Regards,
Muhammad ijaz

Support Developer, Saaspose
Sialkot Team
http://www.saaspose.com

Hi Allen,

Is this issue resolved at your end? If you still need any further assistance, please do let us know. We'll be glad to help you.

Thanks & Regards
Shahzad Latif
Saaspose Support Team.