PHP接收和发送数据

我有以下 php 代码,它将数据发送到潜在客户工具。


<?php


$curl = curl_init();


curl_setopt_array($curl, array(

  CURLOPT_URL => "https://mkt.university-private.internal/form/submit",                                                                                                                                                                                                                                                                                                                                                                           CURLOPT_RETURNTRANSFER => true,

  CURLOPT_ENCODING => "",

  CURLOPT_MAXREDIRS => 10,

  CURLOPT_TIMEOUT => 0,

  CURLOPT_FOLLOWLOCATION => true,

  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

  CURLOPT_CUSTOMREQUEST => "POST",

  CURLOPT_POSTFIELDS => array('mauticform[f_email]' => 'gbsilva@gmail.com','mauticform[f_name]' => 'Gabriel','mauticform[formId]' => '5'),

  CURLOPT_HTTPHEADER => array(

    "X-Forwarded-For: 91.92.103.192"

  ),

));


$response = curl_exec($curl);


curl_close($curl);

echo $response;

问题是我必须在 php 脚本中手动输入数据。


我现在有一个 CRM,它执行 POST 并以正文形式数据发送以下数据:


email=gbsilva@40gmail.com&name=Gabriel&IP=91.92.103.192&formId=5


我需要的是我的 PHP 代码接受接收具有上述这些值的 CRM 帖子,并使用来自 CRM 的数据在我的潜在客户工具中发出请求。


在我的 erp 上,我可以调用一个 url,我将调用我的 script.php 的 url


他需要在发送转换之前将字段的名称放在这个命名法之间,leads 工具只接受具有这个命名法的字段:


mauticform[f_FIELDNAME]


谁能帮忙


慕尼黑8549860
浏览 130回答 2
2回答

互换的青春

非常简单只需要利用$_POST将值传递给变量然后使用它<?php$P_email = $_POST['email'];$P_name = $_POST['name'];$P_formId = $_POST['formId'];$P_ip = $_POST['IP'];$curl = curl_init();curl_setopt_array($curl, array(&nbsp; CURLOPT_URL => "https://mkt.university-private.internal/form/submit",&nbsp; &nbsp;&nbsp; //..hidden&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; CURLOPT_POSTFIELDS => array('mauticform[f_email]' => $P_email,'mauticform[f_name]' => $P_name,'mauticform[formId]' => $P_formId),&nbsp; //hidden&nbsp; //*update* FOR IP&nbsp; CURLOPT_HTTPHEADER => array(&nbsp; &nbsp; "X-Forwarded-For: $P_ip"&nbsp; ),));//..更新:所以要解决动态变量名称//Create an array to hold the name=value pairs$P_arr = [];//Loop over $_POST and populate $P_arrforeach($_POST as $key=>$value){&nbsp; &nbsp; $P_arr[$key] = $value;&nbsp;&nbsp; &nbsp;// $key will run through all those keys' values you sent //name ,email ..&nbsp; &nbsp;// so will $value but on the literals like "gbsilva@40gmail.com", "Gabriel"}/* We have now an array of key value pairs */// adjust the KEYs to "mauticform"'s format before using$mauticformArr = [];foreach($P_arr as $key=>$value){&nbsp; &nbsp;if($key != 'IP'){&nbsp; &nbsp; &nbsp; if($key!= 'formId')&nbsp; &nbsp; &nbsp; &nbsp; $mauticformArr['mauticform[f_'.$key .']'] = $value;&nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; $mauticformArr['mauticform['.$key .']'] = $value;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;}}// Then use inside you code ascurl_setopt_array($curl, array(&nbsp; CURLOPT_URL => "https://mkt.university-private.internal/form/submit",&nbsp; &nbsp;&nbsp; //..hidden&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;CURLOPT_POSTFIELDS => $mauticformArr,&nbsp; //..hidden&nbsp;&nbsp; //..

慕慕森

您可能会发现“Guzzle”比实际使用 CURL 效果更好......
打开App,查看更多内容
随时随地看视频慕课网APP