I am generating leads via website forms. The old system is to get the leads emailed using the below code:
<?php
if(isset($_POST['submit'])) {
$to = "example@example.com";
$subject = "Email Subject";
// data the visitor provided
$title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
$first_name = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
$last_name = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING);
$when_to_call = filter_var($_POST['whentocall'], FILTER_SANITIZE_STRING);
$house_number = filter_var($_POST['housenumber'], FILTER_SANITIZE_STRING);
$postcode = filter_var($_POST['postcode'], FILTER_SANITIZE_STRING);
$kw = filter_var($_POST['kw'], FILTER_SANITIZE_STRING);
$pos = filter_var($_POST['pos'], FILTER_SANITIZE_STRING);
$device = filter_var($_POST['device'], FILTER_SANITIZE_STRING);
$adgroup = filter_var($_POST['adgroup'], FILTER_SANITIZE_STRING);
//constructing the message
$body = " From: $title $first_name $last_name
Email: $email
Phone: $phone
When to call: $when_to_call
House Name/Number: $house_number
Postcode: $postcode
Keyword: $kw
Position: $pos
Device: $device
ad group: $adgroup";
// ...and away we go!
mail($to, $subject, $body);
// redirect to confirmation
header('Location: callbackconfirm.php');
} else {
}
?>
Our new system is to send the leads via XML straight into an online CRM, here is the code I have which works just fine:
<?php
echo "Thank you for your submission ".$_POST["firstname"];
$XML = "";
$XML .= "<Application><Cases><Case>";
$XML .= "<CreateCase>1</CreateCase>";
$XML .= "<FirstName>".$_POST["firstname"]."</FirstName>";
$XML .= "<LastName>".$_POST["surname"]."</LastName>";
$XML .= "<HomeTelephone>".$_POST["phone"]."</HomeTelephone>";
$XML .= "<HouseNumber>".$_POST["housenumber"]."</HouseNumber>";
$XML .= "<PostCode>".$_POST["postcode"]."</PostCode>";
$XML .= "<KEYWORD>".$_POST["kw"]."</KEYWORD>";
$XML .= "<ADGROUP>".$_POST["adgroup"]."</ADGROUP>";
$XML .= "<DEVICE>".$_POST["device"]."</DEVICE>";
$XML .= "<POSITION>".$_POST["pos"]."</POSITION>";
$XML .= "<URL>".$_POST["currentUrl"]."</URL>";
$XML .= "<IPADDRESS>".$_POST["ipaddress"]."</IPADDRESS>";
$XML .= "<SourceName>".$_POST["adgroup"]."</SourceName>";
$XML .= "</Case></Cases></Application>";
postXML($XML);
function postXML($XML){
$url = "CRM URL";
$headers = array(
"Content-Type: application/x-www-form-urlencoded"
);
$post = http_build_query(
array("XMLApplication" => $XML)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}
?>
What I need is to be able to merge these two together so that when the magic submit button is pressed, it sends this XML feed into the software and generates the email at the same time.
I have tried and failed, can anybody help?
Many thanks