Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Modified PHP API Example #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Modified PHP API Example #39

wants to merge 4 commits into from

Conversation

jserrao
Copy link

@jserrao jserrao commented Jul 19, 2017

I modified my sample to better match PSR-2 standards and other tweaks requested in last PR (#37).

* To determine yours, check the last 3 digits of your API key
* ================
*/
$url = 'https://us5.api.mailchimp.com/3.0/lists/' . list_id . '/members/';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider setting the us5 portion to a variable like list_id and api_key because it can change from user to user. For example, my list is us6

*/
$pfb_data = array(
'email_address' => $_POST['emailname'],
'status' => 'pending',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider adding 'interests' => $interests, where $interests may be built like this:

  // Build the $interests array
  $interests = [];
  $interestArr = isset($_POST['interests']) && is_array($_POST['interests']) ? $_POST['interests'] : [];
  foreach ($interestArr as $id) {
    $interests[$id] = true;
  }

* ================
*/
$pfb_data = array(
'email_address' => $_POST['emailname'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider using $_POST['email'] because 1) I'm not sure what emailname is, and 2) it's a good practice to have your email input with the name="email" for autofilling purposes

*/
$pfb_data = array(
'email_address' => $_POST['emailname'],
'status' => 'pending',
Copy link

@kevnk kevnk Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pending instead of subscribed? The reason I'm using this file is to subscribe users with ajax without the required double opt-in, so subscribed status is perfect for my use case.

* ================
*/
define("api_key", "your-api-key-here");
define("list_id", "your-list-id-here");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually see these constants in ALL_CAPS_CASE, but I guess that's a preference thing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants