0

Im using wordpress with the activecampaign plugin. Im trying to use a webhook to send a contacts email data to a php page where i can do something with this information. How do i receive data structured as following in php:

Encoded

contact%5Bid%5D=67330&contact%5Bemail%5D=asdf%40d.nl&contact%5Bfirst_name%5D=sadf&contact%5Blast_name%5D=asdf&contact%5Bphone%5D=%2B1063494959&contact%5Borgname%5D=&contact%5Bcustomer_acct_name%5D=&contact%5Btags%5D=&contact%5Bip4%5D=0.0.0.0&seriesid=266

Decoded

contact[id]=67330&contact[email]=asdf@d.nl&contact[first_name]=sadf&contact[last_name]=asdf&contact[phone]=+1624567935&contact[orgname]=&contact[customer_acct_name]=&contact[tags]=&contact[ip4]=0.0.0.0&seriesid=266

I tried using $email = $_POST["contact[email]"]; but no luck.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
jmelger
  • 87
  • 5
  • Your question is not clear at all. what do you need? where is your code to generate the output? Help us help you by uploading the code and make the question more clear. – waanofii.tech Aug 14 '20 at 16:50
  • I need to know how i call the post variables. $_POST["contact[email]"]; like that. The data in code blocks is the raw post data which i want to receive in php. I want to know how i store this in php variables. – jmelger Aug 15 '20 at 03:34
  • As i said. Its a webhook from a plugin. It sends post data from the plugin to a specified url. In this case my own php page where i want to receive the data. – jmelger Aug 15 '20 at 03:35

2 Answers2

1

Here is the thing whenever you use a bracket as identifier for a data to be sent in POST it's going to form the associative array like $key=>$value relation in your case for example if contact[email] has been received through post request it will be like associative array of a form $contact=>$email which can be accessed in this case by using $_POST['contact']['email'] because the data will take the following array structure Array ( [contact] => Array ( [email] => someone@somewhere.com ) )

to sum up things your above request will work if you just copied the following

$email=$_POST['contact']['email'];

If the answer worked don't forget to accept and up vote so that other could benefit and easily spot the right answer. if you faced further problem don't hesitate to ask in comment. peace ;-)

waanofii.tech
  • 311
  • 1
  • 12
-1

You could use explode with urldecode functions:

Look at the example:

$query = "my=apples&are=green+and+red";

foreach (explode('&', $query) as $chunk) {
    $param = explode("=", $chunk);

    if ($param) {
        printf("Param\"%s\" - \"%s\"<br/>\n", urldecode($param[0]), urldecode($param[1]));
    }
}
Andrii Sukhoi
  • 749
  • 5
  • 14