HTTP ERROR CODE 400 php

0 respostas
php
R

Boa tarde, estou tentando usar sistema de newsletter com php, mas quando faço o teste dame o erro de bad request, não sei porque peço ajuda

<?php session_start(); if(isset($_POST['botao_news'])){ $email = $_POST['email']; if(!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL) === false){ // MailChimp API credentials $apiKey = 'd36a971c0025dc5de6ea9ba814559e10-us17'; $listID = 'b7f6f87f77'; // MailChimp API URL $memberID = md5(strtolower($email)); $dataCenter = substr($apiKey,strpos($apiKey,'-')+1); $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID; // member information $json = json_encode([ 'email_address' => $email, 'status' => 'subscribed', 'merge_fields' => [ /*'FNAME' => $fname, 'LNAME' => $lname*/ ] ]); // 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, $json); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); echo $httpCode; // store the status message based on response code if ($httpCode == 200) { $_SESSION['msg'] = '

You have successfully subscribed to ETC-MZ.

'; } else { switch ($httpCode) { case 214: $msg = 'You are already subscribed.'; break; default: $msg = 'Some problem occurred, please try again.'; break; } $_SESSION['msg'] = '

'.$msg.'

'; } }else{ $_SESSION['msg'] = '

Please enter valid email address....

'; } echo $_SESSION['msg']; } // redirect to homepage //header('location:leilao.php'); ?>
Criado 19 de dezembro de 2017
Respostas 0
Participantes 1