I'm having an issue mail()ing XML in the ADF format to my CRM tool.

In a nutshell, ADF stands for Auto-Lead Data Format (http://www.autojini.com/ADF1_0.pdf) and is XML based and used by many auto dealer CRMs.

The XML will work when sent as an email from Gmail over to the CRM tool, but when I actually email it using PHP, it's not recognizing it correctly and I'm not getting the customers information (besides their phone number) nor is the correct service provider showing.

I've been working on this for about 30 hours now and I can't figure it out.

I'd really appreciate your help!!

applyprocess.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$fname=strip_tags($_GET['fname']);
$lname=strip_tags($_GET['lname']);
$email=strip_tags($_GET['email']);
$phone=strip_tags($_GET['phone']);
$isodate=date("Y-m-d\TH:i:sP");

$adf  = <<<ADF
<?xml version = "1.0"?>\n
<?adf version="1.0"?>\n
<adf>\n
<prospect>\n
<id sequence="1" source="XXXXXXXXX">360</id>\n
<customer>\n
<contact>\n
<name part="first">Eleadtester</name>\n
<name part="last">Jedimaster</name>\n
<email preferredcontact="1"></email>\n
<phone type="voice">1112225555</phone>\n
</contact>\n
<timeframe>2 weeks</timeframe>\n
</customer>\n
<vendor>\n
<vendorname>XXXXXXXXXXX</vendorname>\n
<contact>\n
<name part="full">XXXXXXXXXXXX</name>\n
<phone type="voice">111-123-1234</phone>\n
<address>\n
<street line="1">orange way</street>\n
<city>my town</city>\n
<regioncode>XX</regioncode>\n
<postalcode>XXX03</postalcode>\n
<country>USA</country>\n
</address>\n
</contact>\n
</vendor>\n
<provider>\n
<name part="full">XXXXXXXXXX</name>\n
<service>XXXXXXXXXXXX</service>\n
</provider>\n
</prospect>\n
</adf>\n
</adf>
ADF;

$headers = "Content-Type: application/xhtml+xml; charset=ISO-8859-1" . "\r\n"; //  encoding=ISO-8859-1
$headers .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";
    
mail("XXXXXXXXXXX@eleadtrack.net","XXX Lead - $isodate",$adf,$headers); 

header("Location: apply.html");

?>

On the CRM side, once this is transferred over and received, in place of the customer name I have "<?adf" in the first name field and last name is empty/"noname".

Thanks for your help,
DealerIT

Solved:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$fname=strip_tags($_GET['fname']);
$lname=strip_tags($_GET['lname']);
$email=strip_tags($_GET['email']);
$phone=ereg_replace("[^0-9]", "", $_GET['phone']); 

$adf  = <<<ADF
<?xml version = "1.0"?>\n
<?adf version="1.0"?>\n
<adf>\n
<prospect>\n
<id sequence="1" source="XXXXXXXXX">360</id>\n
<customer>\n
<contact>\n
<name part="first">Eleadtester</name>\n
<name part="last">Jedimaster</name>\n
<email preferredcontact="1"></email>\n
<phone type="voice">1112225555</phone>\n
</contact>\n
<timeframe>2 weeks</timeframe>\n
</customer>\n
<vendor>\n
<vendorname>XXXXXXXXXXX</vendorname>\n
<contact>\n
<name part="full">XXXXXXXXXXXX</name>\n
<phone type="voice">111-123-1234</phone>\n
<address>\n
<street line="1">orange way</street>\n
<city>my town</city>\n
<regioncode>XX</regioncode>\n
<postalcode>XXX03</postalcode>\n
<country>USA</country>\n
</address>\n
</contact>\n
</vendor>\n
<provider>\n
<name part="full">XXXXXXXXXX</name>\n
<service>XXXXXXXXXXXX</service>\n
</provider>\n
</prospect>\n
</adf>\n
</adf>
ADF;

   
mail("XXXXXXXXXXX@eleadtrack.net","",$adf); 

header("Location: apply.html");

?>

The main problem was the fact that the subject line needed to be empty on the email, and was parsing incorrectly because of such. I'm sure this varies from CRM to CRM, but eLeadCRM in particular in this case needed an empty subject line and no headers.

Thanks,

DealerIT

Please examine this code below. This is a working example I made on one of my clients. This may not what you need but you may use this code as a reference.

<?php
        $arrDealer = getdealer($_POST['cmDealer'], $db);

        $filename = 'Lead-'.time().'.xml';
        //Send email with attched adf xml
        $xmlDoc = new DOMDocument("1.0", "UTF-8");
        $xmlDoc->preserveWhiteSpace = false;
        $xmlDoc->formatOutput = true;       
        $doc = $xmlDoc->createProcessingInstruction('ADF', 'VERSION="1.0"');
        $xmlDoc->appendChild($doc);

        //create the root element
        $root = $xmlDoc->appendChild($xmlDoc->createElement("adf"));

        $prospect = $root->appendChild($xmlDoc->createElement("prospect"));

        $id = $prospect->appendChild($xmlDoc->createElement("id"));
        $id->setAttribute("source", "Loan Application");
        $id->appendChild($xmlDoc->createTextNode(md5(time())));

        $prospect->appendChild($xmlDoc->createElement("requestdate"))->appendChild($xmlDoc->createTextNode(date(DATE_ATOM)));

        $customer = getCustomer($xmlDoc, $prospect, $_POST);
        $provider = getProvider($xmlDoc, $prospect, $arrDealer);
        $vendor = getVendor($xmlDoc, $prospect);

        $xmlDoc->save($filename);

        //Send Email
        $to = $_POST['dealerName']."<".$_POST['dealerEmail'].">,xxxx <xxx@xxx.com>";
        $subject = "New Lead Requests";
        $headers = "From: xxxx xxxx<xx@xxx.com>\r\nReply-To: xxxx xxxx<xx@xxx.com>";

        $message = file_get_contents($filename);

        //send the email
        $mail = @mail( $to, $subject , $message, $headers );
        @unlink($filename);     

    }
}

function getdealer($id, $db){
    $row = array();
    $strSQL = "SELECT dlID, dlFirstname, dlMI, dlLastname, dlHeaderName, dlEmail, dlProviderEmail, dlProviderUrl, dlProviderService, dlProviderName FROM Dealers WHERE dlID = ".trim($id);
    if ($result = $db->query($strSQL)) {
        $row = $result->fetch_assoc();
        $result->close();
    }
    $db->close();
    return $row;
}

function getVendor($xmlDoc, $prospect) {
    $vendor = $prospect->appendChild($xmlDoc->createElement("vendor"));

    $vendorname = $vendor->appendChild($xmlDoc->createElement("vendorname"));
    $vendorname->appendChild($xmlDoc->createTextNode('Loan Application'));

    $contact = $vendor->appendChild($xmlDoc->createElement("contact"));
    $name = $contact->appendChild($xmlDoc->createElement("name"));
    $name->appendChild($xmlDoc->createTextNode($_SERVER['HTTP_HOST']));
    $name->setAttribute("part", "full");

    return $vendor;
}

function getProvider($xmlDoc, $prospect, $arrProvider) {
    //print_r($arrProvider);
    $provider = $prospect->appendChild($xmlDoc->createElement("provider"));

    $name = $provider->appendChild($xmlDoc->createElement("name"));
    $name->appendChild($xmlDoc->createTextNode($arrProvider['dlProviderName']));
    $name->setAttribute("part", "full");

    $service = $provider->appendChild($xmlDoc->createElement("service"));
    $service->appendChild($xmlDoc->createTextNode($arrProvider['dlProviderService']));

    $url = $provider->appendChild($xmlDoc->createElement("url"));
    $url->appendChild($xmlDoc->createTextNode($arrProvider['dlProviderUrl']));

    $email = $provider->appendChild($xmlDoc->createElement("email"));
    $email->appendChild($xmlDoc->createTextNode($arrProvider['dlProviderEmail']));

    $contact = $provider->appendChild($xmlDoc->createElement("contact"));
    $contact->setAttribute("primarycontact", "1");

    $name = $contact->appendChild($xmlDoc->createElement("name"));
    $name->appendChild($xmlDoc->createTextNode($arrProvider['dlFirstname'].' '.$arrProvider['dlLastname']));
    $name->setAttribute("part", "full");

    $email = $contact->appendChild($xmlDoc->createElement("email"));
    $email->appendChild($xmlDoc->createTextNode($arrProvider['dlEmail']));

    return $provider;
}

function getCustomer($xmlDoc, $prospect, $arrCustomer) {
    $customer = $prospect->appendChild($xmlDoc->createElement("customer"));

    $contact = $customer->appendChild($xmlDoc->createElement("contact"));
    $first = $contact->appendChild($xmlDoc->createElement("name"));
    $first->appendChild($xmlDoc->createTextNode($arrCustomer['first_name']));
    $first->setAttribute("part", "first");

    $last = $contact->appendChild($xmlDoc->createElement("name"));
    $last->appendChild($xmlDoc->createTextNode($arrCustomer['last_name']));
    $last->setAttribute("part", "last");

    $email = $contact->appendChild($xmlDoc->createElement("email"));
    $email->appendChild($xmlDoc->createTextNode($arrCustomer['email']));

    $phone = $contact->appendChild($xmlDoc->createElement("phone"));
    $phone->appendChild($xmlDoc->createTextNode($arrCustomer['phone1']));
    $phone->setAttribute("type", "phone");

    $cell = $contact->appendChild($xmlDoc->createElement("phone"));
    $cell->appendChild($xmlDoc->createTextNode($arrCustomer['phone2']));
    $cell->setAttribute("type", "cellphone");

    $home = $contact->appendChild($xmlDoc->createElement("address"));
    $home->setAttribute("type", "home");

    $street = $home->appendChild($xmlDoc->createElement("street"));
    $street->appendChild($xmlDoc->createTextNode($arrCustomer['address']));

    $city = $home->appendChild($xmlDoc->createElement("city"));
    $city->appendChild($xmlDoc->createTextNode($arrCustomer['city']));  

    $region = $home->appendChild($xmlDoc->createElement("regioncode"));
    $region->appendChild($xmlDoc->createTextNode($arrCustomer['state']));

    $postal = $home->appendChild($xmlDoc->createElement("postalcode"));
    $postal->appendChild($xmlDoc->createTextNode($arrCustomer['zipcode']));

    $country = $home->appendChild($xmlDoc->createElement("country"));
    $country->appendChild($xmlDoc->createTextNode($arrCustomer['state']));  

    $comments = $customer->appendChild($xmlDoc->createElement("comments"));
    $comments->appendChild($xmlDoc->createTextNode($arrCustomer['extra_info']));

    return $customer;
}
?>

This will be the output sent into email:

<?xml version="1.0" encoding="UTF-8"?>
<?ADF VERSION="1.0"?>
<adf>
  <prospect>
    <id source="Loan Application">b9ca7505b2177e6e8c0e463f8f71ddd3</id>
    <requestdate>2012-11-09T05:42:09-05:00</requestdate>
    <customer>
      <contact>
        <name part="first">Yanni</name>
        <name part="last">Calantaol</name>
        <email>xxxxx</email>
        <phone type="phone">555-222-1234</phone>
        <phone type="cellphone">555-222-1234</phone>
        <address type="home">
          <street>Saabyle Street</street>
          <city>Iligan City</city>
          <regioncode>AL</regioncode>
          <postalcode>92000</postalcode>
          <country>AL</country>
        </address>
      </contact>
      <comments>Comments / Extra Information&#13;
        Include additional information necessary in the box&#13;
        provided to the right. Some examples:</comments>
    </customer>
    <provider>
      <name part="full">xxxx</name>
      <service>xxxx</service>
      <url>xxxx</url>
      <email>xxxx</email>
      <contact primarycontact="1">
        <name part="full">xxxx</name>
        <email>xxxx</email>
      </contact>
    </provider>
    <vendor>
      <vendorname>Loan Application</vendorname>
      <contact>
        <name part="full">xxxxx</name>
      </contact>
    </vendor>
  </prospect>
</adf>

Can anyone assist in how to set the email to send to ReyRey which is Reynolds and Reynolds CRM tool? We have a new tool that captures data on the lot using tablets. We want to push this through email to ReyRey so the record is waiting to work once inside. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.