How can I merge these two PHP snippets together to both send an email and send XML to a database? -


i generating leads via website forms. old system leads emailed using below code:

<?php if(isset($_post['submit'])) { $to = "example@example.com"; $subject = "email subject";  // data 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 message $body = " from: $title $first_name $last_name\n\n email: $email\n\n phone: $phone\n\n when call: $when_to_call\n\n house name/number: $house_number\n\n postcode: $postcode \n\n keyword: $kw \n\n position: $pos \n\n device: $device \n\n ad group: $adgroup";  // ...and away go! mail($to, $subject, $body);  // redirect confirmation header('location: callbackconfirm.php'); } else {  } ?> 

our new system send leads via xml straight online crm, here code have works fine:

<?php echo "thank 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 need able merge these 2 when magic submit button pressed, sends xml feed software , generates email @ same time.

i have tried , failed, can help?

many thanks

merge code , remove xml echo?

<?php if(isset($_post['submit'])) { $to = "example@example.com"; $subject = "email subject";  // data 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 message $body = " from: $title $first_name $last_name\n\n email: $email\n\n phone: $phone\n\n when call: $when_to_call\n\n house name/number: $house_number\n\n postcode: $postcode \n\n keyword: $kw \n\n position: $pos \n\n device: $device \n\n ad group: $adgroup";  // ...and away go! mail($to, $subject, $body);  $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>";      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);  postxml($xml);  // redirect confirmation header('location: callbackconfirm.php'); } else {  } ?> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -