MailChimp API Integration in PHP - Tutorial in Hindi (ok)

https://www.youtube.com/watch?v=Y5hrSqLk29Y&t=2s

Đọc bài liên kết: https://learnemail.gitbook.io/emailphp/mailchimp-api-ok

File đã hoàn thành :)

Hướng dẫn: Link chính: https://github.com/drewm/mailchimp-api Bước 0: Chuẩn bị form submit và file php Bước 1: composer require drewm/mailchimp-api && composer install && require("vendor/autoload.php") Bước 2: Lấy api_key vào link https://us20.admin.mailchimp.com/account/api/ và lấy 1 cái sử dụng Bước 3: Lấy list_id vào link https://us20.admin.mailchimp.com/lists/ để tìm

C:\xampp\htdocs\code\index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- Latest compiled and minified CSS & JS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://code.jquery.com/jquery.js"></script>
</head>
<body>
  <div class="container">
    <div class="col-sm-6 col-sm-offset-3">
      <h1 class="text-center">MailChimp</h1>
      <form action="form-submit.php" method="POST" role="form">
        <legend>Form title</legend>
        <div class="form-group">
          <label for="fname">First Name</label>
          <input type="text" class="form-control" id="fname" name="fname" placeholder="First Name">
        </div>
        <div class="form-group">
          <label for="lname">Last Name</label>
          <input type="text" class="form-control" id="lname" name="lname" placeholder="Last Name">
        </div>
        <div class="form-group">
          <label for="mail">Email</label>
          <input type="mail" class="form-control" id="email" name="email" placeholder="Email">
        </div>
        <button type="submit" class="btn btn-primary">Submit</button>
      </form>
    </div>
  </div>
</body>
</html>

C:\xampp\htdocs\email\form-submit.php

<?php
require("vendor/autoload.php");
use \DrewM\MailChimp\MailChimp;
$api_key   = "2906e09b81e42266013f0ac9128ecf6c-us20";
$list_id   = 'ddf38752d8';
$MailChimp = new MailChimp($api_key);
if ($_POST) {
  $fname  = $_POST['fname'];
  $lname  = $_POST['lname'];
  $email  = $_POST['email'];
  $result = $MailChimp->post("lists/$list_id/members", [
    'email_address' => $email,
    'merge_fields' => ['FNAME'=> $fname, 'LNAME'=>$lname],
    'status'        => 'subscribed',
  ]);
  if ($MailChimp->success()) {
    print_r($result);
  } else {
    echo $MailChimp->getLastError();
  }
}
?>

Kết quả:


Array
(
    [id] => 47b7d4b1828876c83b6d3938528485d6
    [email_address] => phamkyanha2@gmail.com
    [unique_email_id] => f673c64454
    [contact_id] => 124572376ab18a8cc7ee5ef4fc0ae792
    [full_name] => Tuong 1 Pham 1
    [web_id] => 551843551
    [email_type] => html
    [status] => subscribed
    [consents_to_one_to_one_messaging] => 1
    [merge_fields] => Array
        (
            [FNAME] => Tuong 1
            [LNAME] => Pham 1
            [ADDRESS] => 
            [PHONE] => 
            [BIRTHDAY] => 
        )

    [stats] => Array
        (
            [avg_open_rate] => 0
            [avg_click_rate] => 0
        )

    [ip_signup] => 
    [timestamp_signup] => 
    [ip_opt] => 171.241.58.190
    [timestamp_opt] => 2022-03-01T09:04:16+00:00
    [member_rating] => 2
    [last_changed] => 2022-03-01T09:04:16+00:00
    [language] => 
    [vip] => 
    [email_client] => 
    [location] => Array
        (
            [latitude] => 0
            [longitude] => 0
            [gmtoff] => 0
            [dstoff] => 0
            [country_code] => 
            [timezone] => 
            [region] => 
        )

    [source] => API - Generic
    [tags_count] => 0
    [tags] => Array
        (
        )

    [list_id] => ddf38752d8
    [_links] => Array
        (
            [0] => Array
                (
                    [rel] => self
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6
                    [method] => GET
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json
                )

            [1] => Array
                (
                    [rel] => parent
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members
                    [method] => GET
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/CollectionResponse.json
                    [schema] => https://us20.api.mailchimp.com/schema/3.0/Paths/Lists/Members/Collection.json
                )

            [2] => Array
                (
                    [rel] => update
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6
                    [method] => PATCH
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json
                    [schema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/PATCH.json
                )

            [3] => Array
                (
                    [rel] => upsert
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6
                    [method] => PUT
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json
                    [schema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/PUT.json
                )

            [4] => Array
                (
                    [rel] => delete
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6
                    [method] => DELETE
                )

            [5] => Array
                (
                    [rel] => activity
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6/activity
                    [method] => GET
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Activity/Response.json
                )

            [6] => Array
                (
                    [rel] => goals
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6/goals
                    [method] => GET
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Goals/Response.json
                )

            [7] => Array
                (
                    [rel] => notes
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6/notes
                    [method] => GET
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Notes/CollectionResponse.json
                )

            [8] => Array
                (
                    [rel] => events
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6/events
                    [method] => POST
                    [targetSchema] => https://us20.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Events/POST.json
                )

            [9] => Array
                (
                    [rel] => delete_permanent
                    [href] => https://us20.api.mailchimp.com/3.0/lists/ddf38752d8/members/47b7d4b1828876c83b6d3938528485d6/actions/delete-permanent
                    [method] => POST
                )

        )

)

Last updated