سؤال

I'm creating a very simple sign up form using Mailchimp's PHP API wrapper. It consists of an email input and a submit button.

<!DOCTYPE>  
<html>
<head>
    <title>Mailchimp API test</title>
</head>
<body>

    <?php 

    $email = $_POST['email'];

    $subscribe = new Mailchimp_Lists();

    $subscribe->subscribe("apikey", "listid", $email);


    ?>

    <form method="post">

        <label for="email">Email:</label>
        <input type="email" name="email" />
        <input type="submit" value="subscribe" />

    </form>

</body>
</html>

I'm getting the following message in my error_log

[05-May-2014 06:48:04 Europe/Berlin] PHP Fatal error:  Class 'Mailchimp_Lists' not found in /Users/Chappell/Websites/MailchimpSandbox/index.php on line 12

I installed the wrapper using composer and the Mailchimp lists.php file is located in vendor/mailchimp/mailchimp/src/Mailchimp/Lists.php

Does anyone with experience of the PHP wrapper know how I can successfully call the subscribe method on my $subscribe object.

هل كانت مفيدة؟

المحلول

I'm not familiar with MailChimp but in order to instantiate any class object you need to include the class. Something like:

include "vendor/mailchimp/mailchimp/src/Mailchimp/Lists.php";
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top