如何将mailchimp与核心php集成

时间:2017-04-26 10:29:55

标签: email integration mailchimp mailchimp-api-v3.0

我需要整合邮件黑猩猩api与核心php我尝试了更多类型的代码,但没有工作。最后,我找到了下面的代码。我已经使用mailchimp创建了一个api密钥,同样也在mailchimp中创建了广告系列,模板和列表。

<script src="jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
    $('#subscribe').submit(function() {
        if (!valid_email_address($("#email").val()))
        {
            $(".message").html('The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.');
        }
        else
        {

            $(".message").html("<span style='color:green;'>Adding your email address...</span>");
            $.ajax({
                url: 'subscribe.php', 
                data: $('#subscribe').serialize(),
                type: 'POST',
                success: function(msg) {
                    if(msg=="success")
                    {
                        $("#email").val("");
                        $(".message").html('<span style="color:green;">You have successfully subscribed to our mailing list.</span>');

                    }
                    else
                    {
                      $(".message").html('The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.');  
                    }
                }
            });
        }

        return false;
    });
});
function valid_email_address(email)
{
    var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
    return pattern.test(email);
}
</script>
<?php
$api_key = "key";
$list_id = "id";
require('inc/MAPI.class.php');
$Mailchimp = @new Mailchimp( $api_key );
echo bool($Mailchimp);

//$Mailchimp_Lists = @new Mailchimp_Lists( $Mailchimp );
//$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']) ) );
if ( ! empty( $subscriber['leid'] ) ) {
   echo "success";
}
else
{
    echo "fail";
}
?>
<div class="message"></div>

<form  role="form" method="post" id="subscribe">

    <input type="email"  id="email" name="email" placeholder="you@yourself.com" value="">
    <button type="submit">SUBSCRIBE</button>

</form>

这是我的代码,但它没有返回,只有错误。请帮帮我。

0 个答案:

没有答案