how to embed mailchimp on custom form

Solutions on MaxInterview for how to embed mailchimp on custom form by the best coders in the world

showing results for - "how to embed mailchimp on custom form"
Benjamin
06 Nov 2019
1Log in to your A2 Hosting account using SSH.
2At the command prompt, type the following commands:
3cd ~
4git clone https://bitbucket.org/mailchimp/mailchimp-api-php.git
5After the git clone command completes, there is a new mailchimp-api-php directory.
6
7Type the following command:
8
9cp -R mailchimp-api-php/src mailchimp
10  
11This command copies the API source code to the separate mailchimp directory (you can actually use any directory name you want). Doing so enables you to pull future updates in the mailchimp-api-php directory for further testing, without overwriting source code referenced directly by your applications.
12To use the MailChimp API in your PHP code, you must include the Mailchimp.php file. Then you can create a Mailchimp object and work with the API. For example, the following code sample demonstrates how to add a new subscriber to an existing list:
13
14<?php
15
16require('mailchimp/Mailchimp.php');    // You may have to modify the path based on your own configuration.
17
18$api_key = "Add your Mailchimp API key here";
19$list_id = "Add your list ID here";
20
21$Mailchimp = new Mailchimp( $api_key );
22$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
23
24try 
25{
26    $subscriber = $Mailchimp_Lists->subscribe(
27        $list_id,
28        array('email' => 'kellykoe@example.com'),      // Specify the e-mail address you want to add to the list.
29        array('FNAME' => 'Kelly', 'LNAME' => 'Koe'),   // Set the first name and last name for the new subscriber.
30        'text',    // Specify the e-mail message type: 'html' or 'text'
31        FALSE,     // Set double opt-in: If this is set to TRUE, the user receives a message to confirm they want to be added to the list.
32        TRUE       // Set update_existing: If this is set to TRUE, existing subscribers are updated in the list. If this is set to FALSE, trying to add an existing subscriber causes an error.
33    );
34} 
35catch (Exception $e) 
36{
37    echo "Caught exception: " . $e;
38}
39
40if ( ! empty($subscriber['leid']) )
41{
42    echo "Subscriber added successfully.";
43}
44else
45{
46    echo "Subscriber add attempt failed.";
47}
48
49?>