admin管理员组

文章数量:1336434

HTML Form Code

<form id="contactForm" action="contact.php" method="post" name="contactForm">
    <div class="form-group">
        <label for="name">Name</label>
        <input id="name" class="form-control" name="name" type="text">
    </div>
    <div class="form-group">
        <label for="email">Email</label>
        <input id="email" class="form-control" name="email" type="email">
    </div>
    <div class="form-group">
        <input class="btn btn-special" type="submit" value="Subscribe">
        <div class="submitting"></div>
    </div>
</form>

PHP Code

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;

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

$mj = new \Mailjet\Client(getenv('123'), getenv('123'), true, ['version' => 'v3']); 
// `123` is a placeholder for demonstration.

$body = [
    'Name' => $name,
    'Properties' => "object",
    'Action' => "addnoforce",
    'Email' => $email
];

$response = $mj->post(Resources::$ContactslistManagecontact, ['id' => 1234, 'body' => $body]);
$response->success() && var_dump($response->getData());
var_dump($response->getData());
?>

I am following the official Mailjet API documentation example. However, I keep receiving the following empty response:

array(0) { }

What I've Tried

  1. Ensured the vendor/autoload.php file is correctly included.
  2. Verified that 1234 (used in the id parameter) corresponds to my Contacts List ID.
  3. Used the official example from Mailjet's GitHub and checked for deprecated usage.

Despite spending hours troubleshooting, I am still unable to resolve this issue. I found this older reference, but it is outdated and doesn't align with the current Mailjet API version.

Questions:

  • Is there an issue with my ContactslistManagecontact endpoint configuration?
  • Am I correctly passing the parameters for the API call?
  • What could be the cause of the empty array(0) response, and how can I debug it further?

Reference Links:

  • Mailjet API Documentation: Manage Contacts
  • Mailjet GitHub Library

Any insights or solutions would be greatly appreciated!

本文标签: phpTrouble Adding a Contact to Mailjet via API array(0) ResponseStack Overflow