KB: Using PHP To Automatically Generate and Email XML Transactions to Email Connector

From RangerMSP Wiki - PSA software for MSPs and IT services providers
Jump to: navigation, search

Introduction

The information on this page will show you the basic steps you need to follow to implement web forms on your Web site that will trigger insert and update events in your RangerMSP database. For example, you can automatically convert contact forms filled by visitor to your Web site into new Account in RangerMSP. This helps automating your work flow and saves the time it takes to manually add the account records.

The examples described below correspond to the XML samples described in the Automatically Creating New Accounts for Web Site Visitors article, effectively completing the automation of the creation of new RangerMSP accounts, this should be considered as "The next step…". If you haven't read the first part, we recommend that you do this prior to continuing to read this article.

Note: This article is using PHP as the scripting language to send the XML API transaction to RangerMSP. It shouldn't be too hard to implement this with other scripting languages such as ASP.

The methods described on this article have some special requirements that must be satisfied prior to applying the information from this article. Here are the requirements:

  • Web Server (Apache, Microsoft® IIS, etc.).
  • PHP Support (we only tested the following with PHP5, though an earlier version may work as well).
  • Email Access (Used by the web server to email the XML email transactions to RangerMSP).
  • RangerMSP Email Connector License.


HTML Forms

By using an HTML Web Form, you can allow your customers to enter the basic contact information into the web form where that information can then be automatically converted to RangerMSP XML formatting (used as an a RangerMSP API transaction, explained below), and emailed automatically to the system to be applied to the RangerMSP database as a new customer account. The way this part works is that the customer enters the information into a basic HTML form, and that form submits the information to a PHP script that processes the information.

In this sample, we're going to gather four different pieces of basic customer contact information that can be used to identify the customer until complete information is gathered from the customer. If you have some experience editing HTML, XML and PHP, then you can edit the samples in this page to your own preferences, and gather any information you require from your customers with the Web form. The information we're going to gather is as follows:

  • Name
  • Company Name
  • Email Address
  • Phone Number
Htmlform.jpg


=====================DISCLAIMER========================

This script is meant for basic app database manipulation. The samples included here can be adjusted to include different data in the transaction; more information on using XML can be found in this link: http://www.rangermsp.com/wiki/API_Code_Samples#XML_samples. We suggest adding mechanisms to the web form to ensure that the user cannot submit the form without first passing a Human Verification test on the same page. Tests like this are available on the internet, and very helpful in preventing spammers from teaching their spam systems how to fill your database with fictitious accounts.

==========================================================

Here's a sample HTML code that will request and submit the information from the customer to a PHP script called XML_Processor.php, located in the same folder as this HTML script. You can open a text file, copy that sample code, save it (like test-form.html ), upload to your Web server and navigate your browser to this file.

HTML Sample

<html><body><font face=Arial size=2> 


<!-- ===========================DISCLAIMER==============================
This script is meant for basic RangerMSP database manipulation. The 
samples included here can be adjusted to include different data in the 
transaction; more information on using XML can be found in this link: 
http://www.RangerMSP.com/wiki/API_Code_Samples#XML_samples.
We suggest adding mechanisms to the web form to ensure that the user 
cannot submit the formwithout first passing a Human Verification test 
on the same page. Tests like this are available on the internet, and 
very helpful in preventing spammers from teaching their spam systems 
how to fill your database with ficticious accounts.
====================================================================== -->

<!--Edit the following line to reflect your PHP script to submit the 
information to -->
<form method="post" action="XML_Processor.php"> 


<!-- ====================================================================
The rest of this information represents the information and field
Geometry that is applied on the Web Form. Editing the below section 
is optional, and only recommended for users with HTML experience; however, 
this is a great way to gather extra information from your users. 
====================================================================== -->

<table bgcolor=#ffffcc align=center> 
<tr><td colspan=2><strong>Contact us using this form:</strong></td></tr> 
<tr><td><font color=red>*</font> Name:</td><td><input size=25 name="contact"></td></tr> 
<tr><td><font color=red>*</font> Email:</td><td><input size=25 name="email"></td></tr> 
<tr><td><font color=red>*</font> Company:</td><td><input size=25 name="company"></td></tr> 
<tr><td><font color=red>*</font> Phone:</td><td><input size=25 name="phone"></td></tr> 
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> 
<tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr> 
</table> 
</form> 
</body> 
</html>


PHP XML Processor Script

Using PHP you can have the web server do all the work needed to take the information submitted by the web form to the PHP script, and automatically create an XML transaction based on that information and email it to the RangerMSP Email Connector, to be applied directly to the RangerMSP database.

The PHP script below has been designed to receive the information entered in the sample web form discussed above, and insert the information into the corresponding part of the XML template. Before using the script, please read the script notes, and adjust the first section to reflect the information needed to send the email message and Insert the API password you configured to be used with RangerMSP API By Email (click here for more info on API settings).

Please review this script, and adjust it freely to your own preferences so that it can facilitate the transfer of the information you need it to transfer to RangerMSP; however, editing this script would require experience in PHP scripting.

Please Note: This script requires PHP5 to be installed on the Web Server.

Copy the Below Script to an empty text file called XML_Processor.php and save it in the same folder as the HTML form.

<?php
//=========================== Notes =================================
//This script is meant for basic RangerMSP database manipulation. The 
//samples included here can be adjusted to include different data in the 
//transaction; more information on using XML can be found in this link: 
//http://www.RangerMSP.com/wiki/API_Code_Samples#XML_samples.
//We suggest adding mechanisms to the web form to ensure that the user 
//cannot submit the form without first passing a Human Verification test 
//on the same page. Samples for tests like this are available on the 
//Internet, and very helpful in preventing spammers from teaching their 
//spam systems how to fill your database with fictitious accounts.


//======================================================================
//======================================================================
//======PLEASE EDIT THIS SECTION TO REFLECT YOUR EMAIL CONNECTOR========
//======================================================================
//======================================================================
//Email Envelope - Edit these values to reflect your RangerMSP Mailbox.
$email_to = 'EmailConnector@YourBusiness.com';
//This line represents the Email Subject to be used on each transaction=
$subject = 'Web Form To RangerMSP Account Email';
//This line should reflect the email address that sends the webform=====
$header = 'From: Webform@YourBusiness.com';
//This line tells the script the API Password for your Email Connector==
$apipasswd = 'your_API_passwd';
//XML Transaction Responses get sent to this email address==============
$readdress = 'Email_Address_To_Send_Responses_to';

//======================================================================
//======================================================================
//=======Constant variables - Do not edit below this comment!===========
//======================================================================
//======================================================================
$company = $_POST['company'];
$contact = $_POST['contact'];
$phone = $_POST['phone'];
$eaddress = $_POST['email'];

//======================================================================
//This section verifies that all data has been entered; if the data has
//been entered, then the script will notify your customer to hit the 
//back button.
if ($company && $contact && $phone && $eaddress) { 
echo "Thank you for submitting your form. You may submit email service requests to our Support Center at:";
echo $email_to; 
} else { 
exit("You have not filled out all the required fields. Place hit your back button and fill out all the required fields.");
}

$xml = '<?xml version="1.0" ?>
<?RangerMSPxml version = "1.0" ?>
 <RangerMSPTransaction>
  <ExternalApplicationName>WebsiteSignup</ExternalApplicationName>
  <SendResponseToEmail>' . $readdress . '</SendResponseToEmail>
  <Password>' . $apipasswd . '</Password>
  <ReturnTransactionID>WebForm - New Account</ReturnTransactionID>
  <DataKind>ACCOUNT</DataKind>
   <RecordData>
   <FLDCRDCOMPANY>' . $company . '</FLDCRDCOMPANY>
   <FLDCRDCONTACT>' . $contact . '</FLDCRDCONTACT>
   <FLDCRDPHONE1>' . $phone . '</FLDCRDPHONE1>
   <FLDCRDEMAIL1>' . $email . '</FLDCRDEMAIL1>
   </RecordData>
 </RangerMSPTransaction>';

mail($email_to, $subject, $xml, $header);

?>


The Next Step

Once your customer has successfully created his/her own account, they can send email messages to your support email address (i.e. the Public Email Address), which is processed automatically by the RangerMSP Email Connector. RangerMSP Email Connector will automatically convert the email message into a service ticket for the newly created account. Please note that Email2Ticket will only work if the ticket is sent from the email account that the customer specified in the Web Form.


Summary

If you've followed this tutorial, then you've successfully facilitated a basic system which allows your new customers to create their own accounts using:

  • An HTML Form which gathers basic account info.
  • A PHP form which processes the info and emails to RangerMSP.
  • The RangerMSP Email Connector which receives and applies the new information.

Associating your customer with RangerMSP opens the door to offering automated service tickets (RangerMSP Email Connector) and personal account monitoring abilities to your customers (RangerMSP Web Interface for Customers).

See Also

Automatically Creating New Accounts for Web Site Visitors
API Code Samples
Email Templates
Emailing your customers using Mail Merge
RangerMSP Web Interface
RangerMSP Email Connector
PHP5 Manual
XML and PHP5 Tutorial