function addContactToList($listID, $contactID)
 {
     $mj = new Mailjet();
     $params = array("method" => "POST", "ContactID" => $contactID, "ListID" => $listID);
     echo "success - contact " . $contactID . " added to the list " . $listID;
     return $mj->listrecipient($params);
 }
Beispiel #2
0
 private function addContactToList($contactID, $listID)
 {
     $mj = new Mailjet();
     $params = array("method" => "POST", "ContactID" => $contactID, "ListID" => $listID, "IsActive" => "True");
     $result = $mj->listrecipient($params);
     /*if ($mj->_response_code == 201)
                     echo "success - contact ".$contactID." added to the list ".$listID;
                 else
                     echo "error - ".$mj->_response_code;
     */
     return $result;
 }
            break;
        case 405:
            $status = "You made a POST request instead of GET, or the reverse.";
            break;
        default:
            $status = "An unknow error occurs.";
    }
    return $status;
}
// We try to create a new contact
$paramsCreateContact = array("method" => "POST", "Email" => $email);
$resultCreateContact = $mailjet->contact($paramsCreateContact);
$returnCreateContact = ['result' => $resultCreateContact, 'response_code' => $mailjet->_response_code, 'message' => mailjetStatusCode($mailjet->_response_code)];
// We get the contact's id by his e-mail
$paramsGetContact = ["method" => "VIEW", "ID" => $email];
$resultGetContact = $mailjet->contact($paramsGetContact);
$result = ['result' => $resultGetContact, 'response_code' => $mailjet->_response_code, 'message' => $message = mailjetStatusCode($mailjet->_response_code)];
if ($resultGetContact != false) {
    $contactID = $resultGetContact->Data[0]->ID;
    $paramsAddContactToList = ["method" => "POST", "ContactID" => $contactID, "ListID" => $listID, "IsActive" => "True"];
    $resultAddContactToList = $mailjet->listrecipient($paramsAddContactToList);
    if ($mailjet->_response_code === 400) {
        $message = ezpI18n::tr("mailjet/inscription", "You have already subscribed, thank you for your interest.");
    } elseif ($mailjet->_response_code === 201) {
        $message = ezpI18n::tr("mailjet/inscription", "You have successfully subscribed to our newsletter, thank you !");
    }
    $result = ['result' => $resultAddContactToList, 'response_code' => $mailjet->_response_code, 'message' => $message];
}
header('Content-type: application/json; charset=utf-8');
echo json_encode($result);
eZExecution::cleanExit();