I have a problem sending the confirmation of the sending of the form, I am not showing any when completing the data or having a shipping problem. The link with Mailchimp if it works perfect.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$cel = $_POST ['cel'];
if($email) {
//Create mailchimp API url
$memberId = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
print $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
//Member info
$data = array(
'email_address'=>$email,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $fname,
'LNAME' => $lname,
'CEL' => $cel
]
);
$jsonString = json_encode($data);
// send a HTTP POST request with curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//Collecting the status
switch ($httpCode) {
case 200:
$msg = '¡Muchisimas gracias! Dentro de poco, nos comunicaremos con vos';
break;
case 214:
$msg = 'Ya estas registrado en nuestra web';
break;
default:
$msg = 'Oops, ocurrio un problema con el mensaje.[msg_code='.$httpCode.']';
break;
}
}
header('location:subscribe.php?msg='.$msg);
}