Skip to content
Advertisement

Extract form field from webhook request

I am getting the following output by this statement

$varname = file_get_contents('php://input');

Output –

You've got a new submission8793892-1=AM+BH&8793892-2=TT&8793893=aman.h340gmail.com&8793894=005-222-2222&8793895=&8793895-1=&8793895-2=&8793895-3=&8793895-4=&8793895-5=&8793895-6=India&8793896=Standard+%28%2430%2Fmonth%29&8793897_0=no&8793897_1=no&8793897_2=no&8793897_3=no&8793897_4=no&8793897_5=no&8793898=&8793899_0=yes&8793900=No&submissionHtml=&entryId=24&submissionId=x5e417c6eae46d8.13907951&geoipcache=%7B%223753571910%22%3A%7B%22ip_ctry%22%3A%22IN%22%2C%22ip_cntry%22%3A%22IND%22%2C%22ip_country%22%3A%22India%22%7D%7D&dateTime=2020-02-10+11%3A53%3A18&sessionGlobalsVars%5Bu_timezone%5D=-4&sessionGlobalsVars%5Bf_refon%5D=0&sessionGlobalsVars%5Bf_adduserinfo%5D=1&sessionGlobalsVars%5Brefid_timestamp%5D=1581349998&sessionGlobalsVars%5Btimestamp%5D=2020-02-10+11%3A53&sessionGlobalsVars%5Bgdrive_sender%5D=noreply%40app.captainform.com&sessionGlobalsVars%5Bgdrive_to%5D=annasawin%40gmail.com&sessionGlobalsVars%5Bgdrive_contact_email%5D=support%40123contactform.com&ses sionGlob

I want to extract Email Id only , how can i get it ? i tried every possible way, but no success. Tried with this, but no success, anyone can help.. thanks

$array=json_decode($varname,true);
$array["8793893"];

Advertisement

Answer

Use the parse_str() function:

$varname = "You've got a new submission8793892-1=AM+BH&8793892-2=TT&8793893=aman.h340gmail.com&8793894=005-222-2222&8793895=&8793895-1=&8793895-2=&8793895-3=&8793895-4=&8793895-5=&8793895-6=India&8793896=Standard+%28%2430%2Fmonth%29&8793897_0=no&8793897_1=no&8793897_2=no&8793897_3=no&8793897_4=no&8793897_5=no&8793898=&8793899_0=yes&8793900=No&submissionHtml=&entryId=24&submissionId=x5e417c6eae46d8.13907951&geoipcache=%7B%223753571910%22%3A%7B%22ip_ctry%22%3A%22IN%22%2C%22ip_cntry%22%3A%22IND%22%2C%22ip_country%22%3A%22India%22%7D%7D&dateTime=2020-02-10+11%3A53%3A18&sessionGlobalsVars%5Bu_timezone%5D=-4&sessionGlobalsVars%5Bf_refon%5D=0&sessionGlobalsVars%5Bf_adduserinfo%5D=1&sessionGlobalsVars%5Brefid_timestamp%5D=1581349998&sessionGlobalsVars%5Btimestamp%5D=2020-02-10+11%3A53&sessionGlobalsVars%5Bgdrive_sender%5D=noreply%40app.captainform.com&sessionGlobalsVars%5Bgdrive_to%5D=annasawin%40gmail.com&sessionGlobalsVars%5Bgdrive_contact_email%5D=support%40123contactform.com&ses sionGlob";
parse_str($varname, $array);
var_dump($array);

This will give you the desired output:

array(28) {
  ["You've_got_a_new_submission8793892-1"]=>
  string(5) "AM BH"
  ["8793892-2"]=>
  string(2) "TT"
  [8793893]=>
  string(18) "aman.h340gmail.com"
  [8793894]=>
  string(12) "005-222-2222"
  [8793895]=>
  string(0) ""
  ["8793895-1"]=>
  string(0) ""
  ["8793895-2"]=>
  string(0) ""
  ["8793895-3"]=>
  string(0) ""
  ["8793895-4"]=>
  string(0) ""
  ["8793895-5"]=>
  string(0) ""
  ["8793895-6"]=>
  string(5) "India"
  [8793896]=>
  string(20) "Standard ($30/month)"
  ["8793897_0"]=>
  string(2) "no"
  ["8793897_1"]=>
  string(2) "no"
  ["8793897_2"]=>
  string(2) "no"
  ["8793897_3"]=>
  string(2) "no"
  ["8793897_4"]=>
  string(2) "no"
  ["8793897_5"]=>
  string(2) "no"
  [8793898]=>
  string(0) ""
  ["8793899_0"]=>
  string(3) "yes"
  [8793900]=>
  string(2) "No"
  ["submissionHtml"]=>
  string(0) ""
  ["entryId"]=>
  string(2) "24"
  ["submissionId"]=>
  string(24) "x5e417c6eae46d8.13907951"
  ["geoipcache"]=>
  string(69) "{"3753571910":{"ip_ctry":"IN","ip_cntry":"IND","ip_country":"India"}}"
  ["dateTime"]=>
  string(19) "2020-02-10 11:53:18"
  ["sessionGlobalsVars"]=>
  array(8) {
    ["u_timezone"]=>
    string(2) "-4"
    ["f_refon"]=>
    string(1) "0"
    ["f_adduserinfo"]=>
    string(1) "1"
    ["refid_timestamp"]=>
    string(10) "1581349998"
    ["timestamp"]=>
    string(16) "2020-02-10 11:53"
    ["gdrive_sender"]=>
    string(27) "noreply@app.captainform.com"
    ["gdrive_to"]=>
    string(19) "annasawin@gmail.com"
    ["gdrive_contact_email"]=>
    string(26) "support@123contactform.com"
  }
  ["ses_sionGlob"]=>
  string(0) ""
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement