}
?>
"><br/>
            htmlBody: <input type="text" name="htmlBody" value="<?php 
if (isset($_REQUEST['htmlBody'])) {
    echo htmlspecialchars($_REQUEST['htmlBody']);
}
?>
"><br/>
            contentType: <input type="text" name="contentType" value="<?php 
if (isset($_REQUEST['contentType'])) {
    echo htmlspecialchars($_REQUEST['contentType']);
}
?>
"><br/>
            mergeContext: <input type="text" name="mergeContext" value="<?php 
if (isset($_REQUEST['mergeContext'])) {
    echo htmlspecialchars($_REQUEST['mergeContext']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::addEmailTemplate($_REQUEST['pieceTitle'], $_REQUEST['categories'], $_REQUEST['fromAddress'], $_REQUEST['toAddress'], $_REQUEST['ccAddress'], $_REQUEST['bccAddress'], $_REQUEST['subject'], $_REQUEST['textBody'], $_REQUEST['htmlBody'], $_REQUEST['contentType'], $_REQUEST['mergeContext']);
    var_dump($out);
}
}
?>
"><br/>
            subject: <input type="text" name="subject" value="<?php 
if (isset($_REQUEST['subject'])) {
    echo htmlspecialchars($_REQUEST['subject']);
}
?>
"><br/>
            htmlBody: <input type="text" name="htmlBody" value="<?php 
if (isset($_REQUEST['htmlBody'])) {
    echo htmlspecialchars($_REQUEST['htmlBody']);
}
?>
"><br/>
            textBody: <input type="text" name="textBody" value="<?php 
if (isset($_REQUEST['textBody'])) {
    echo htmlspecialchars($_REQUEST['textBody']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::sendEmail($_REQUEST['contactList'], $_REQUEST['fromAddress'], $_REQUEST['toAddress'], $_REQUEST['ccAddresses'], $_REQUEST['bccAddresses'], $_REQUEST['contentType'], $_REQUEST['subject'], $_REQUEST['htmlBody'], $_REQUEST['textBody']);
    var_dump($out);
}
}
?>
"><br/>
            subject: <input type="text" name="subject" value="<?php 
if (isset($_REQUEST['subject'])) {
    echo htmlspecialchars($_REQUEST['subject']);
}
?>
"><br/>
            htmlBody: <input type="text" name="htmlBody" value="<?php 
if (isset($_REQUEST['htmlBody'])) {
    echo htmlspecialchars($_REQUEST['htmlBody']);
}
?>
"><br/>
            textBody: <input type="text" name="textBody" value="<?php 
if (isset($_REQUEST['textBody'])) {
    echo htmlspecialchars($_REQUEST['textBody']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::createEmailTemplate($_REQUEST['templateTitle'], $_REQUEST['visibility'], $_REQUEST['fromAddress'], $_REQUEST['toAddress'], $_REQUEST['ccAddresses'], $_REQUEST['bccAddresses'], $_REQUEST['contentType'], $_REQUEST['subject'], $_REQUEST['htmlBody'], $_REQUEST['textBody']);
    var_dump($out);
}
<form>
            email: <input type="text" name="email" value="<?php 
if (isset($_REQUEST['email'])) {
    echo htmlspecialchars($_REQUEST['email']);
}
?>
"><br/>
            reason: <input type="text" name="reason" value="<?php 
if (isset($_REQUEST['reason'])) {
    echo htmlspecialchars($_REQUEST['reason']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::optOut($_REQUEST['email'], $_REQUEST['reason']);
    var_dump($out);
}
<form>
            email: <input type="text" name="email" value="<?php 
if (isset($_REQUEST['email'])) {
    echo htmlspecialchars($_REQUEST['email']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::getOptStatus($_REQUEST['email']);
    var_dump($out);
}
<form>
            mergeContext: <input type="text" name="mergeContext" value="<?php 
if (isset($_REQUEST['mergeContext'])) {
    echo htmlspecialchars($_REQUEST['mergeContext']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::getAvailableMergeFields($_REQUEST['mergeContext']);
    var_dump($out);
}
<form>
            templateId: <input type="text" name="templateId" value="<?php 
if (isset($_REQUEST['templateId'])) {
    echo htmlspecialchars($_REQUEST['templateId']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::getEmailTemplate($_REQUEST['templateId']);
    var_dump($out);
}
<form>
            email: <input type="text" name="email" value="<?php 
if (isset($_REQUEST['email'])) {
    echo htmlspecialchars($_REQUEST['email']);
}
?>
"><br/>
            permissionReason: <input type="text" name="permissionReason" value="<?php 
if (isset($_REQUEST['permissionReason'])) {
    echo htmlspecialchars($_REQUEST['permissionReason']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::optIn($_REQUEST['email'], $_REQUEST['permissionReason']);
    var_dump($out);
}
}
?>
"><br/>
            receivedDate: <input type="text" name="receivedDate" value="<?php 
if (isset($_REQUEST['receivedDate'])) {
    echo htmlspecialchars($_REQUEST['receivedDate']);
}
?>
"><br/>
            sentDate: <input type="text" name="sentDate" value="<?php 
if (isset($_REQUEST['sentDate'])) {
    echo htmlspecialchars($_REQUEST['sentDate']);
}
?>
"><br/>
            emailSentType: <input type="text" name="emailSentType" value="<?php 
if (isset($_REQUEST['emailSentType'])) {
    echo htmlspecialchars($_REQUEST['emailSentType']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_APIEmailService::attachEmail($_REQUEST['contactId'], $_REQUEST['fromName'], $_REQUEST['fromAddress'], $_REQUEST['toAddress'], $_REQUEST['ccAddresses'], $_REQUEST['bccAddresses'], $_REQUEST['contentType'], $_REQUEST['subject'], $_REQUEST['htmlBody'], $_REQUEST['textBody'], $_REQUEST['header'], $_REQUEST['receivedDate'], $_REQUEST['sentDate'], $_REQUEST['emailSentType']);
    var_dump($out);
}
 if ($_GET['object'] == 'Template') {
     echo 'Exporting email templates into files.' . "<br/>";
     $page = 0;
     do {
         echo 'Fetching page ' . $page . '<br/>';
         flush();
         $object_fields = $object->getFields();
         if (in_array('Id', $object_fields)) {
             $results = Infusionsoft_DataService::queryWithOrderBy(new $class_name(), array('Id' => '%'), 'Id', true, 100, $page);
         } else {
             $results = Infusionsoft_DataService::queryWithOrderBy(new $class_name(), array($object_fields[0] => '%'), $object_fields[0], true, 100, $page);
         }
         foreach ($results as $result) {
             if ($result->PieceType == 'Email' && substr($result->PieceTitle, 0, 14) != 'An email draft' && substr($result->PieceTitle, 0, 12) != 'API Template' && $result->Categories != 'Product Fulfillment') {
                 try {
                     $template = Infusionsoft_APIEmailService::getEmailTemplate($result->Id);
                     $file_name = "../exports/" . $_GET['object'] . '_' . $result->Id . '_' . date('Ymd-h.i.s') . '.txt';
                     echo 'Creating file: ' . $file_name . '<br/>';
                     $file = fopen($file_name, 'w');
                     fwrite($file, 'Title: ' . $template['pieceTitle'] . "\n");
                     fwrite($file, 'Categories: ' . $template['categories'] . "\n");
                     fwrite($file, 'From: ' . $template['fromAddress'] . "\n");
                     fwrite($file, 'To: ' . $template['toAddress'] . "\n");
                     fwrite($file, 'Cc: ' . $template['ccAddress'] . "\n");
                     fwrite($file, 'Bcc: ' . $template['bccAddress'] . "\n");
                     fwrite($file, 'Subject: ' . $template['subject'] . "\n\n");
                     fwrite($file, 'Text Body: ' . $template['textBody'] . "\n\n\n");
                     fwrite($file, 'Html Body: ' . $template['htmlBody'] . "\n");
                     fclose($file);
                 } catch (Exception $e) {
                     echo "Could not export template: " . $result->Id . "<br/>";