首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress + Constant Contact PHP SDK包含路径

Wordpress + Constant Contact PHP SDK包含路径
EN

Stack Overflow用户
提问于 2014-10-10 08:23:43
回答 1查看 283关注 0票数 0

我目前正在尝试将Constant Contact PHP sdk实现到wordpress站点中。询问SDK的一部分,你必须包含一些核心PHP文件才能使电子邮件代码工作。如果没有找到这些文件,页面就会死掉,不会出现PHP错误。目前,我在站点主题的根目录下有一个名为"src“9的文件夹(他们的命名约定不是我的) (/wp-content/themes/mytheme/src...)。

下面是调用这些文件的电子邮件表单代码:

代码语言:javascript
复制
<?php
// require the autoloader
require_once(TEMPLATEPATH . '/src/Ctct/autoload.php');

use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;

// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "XXXXXX");
define("ACCESS_TOKEN", "XXXXXX");

$cc = new ConstantContact(APIKEY);

// attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
try {
    $lists = $cc->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
    foreach ($ex->getErrors() as $error) {
        print_r($error);
    }
}

// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
    $action = "Getting Contact By Email Address";
    try {
        // check to see if a contact with the email addess already exists in the account
        $response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['email']);

        // create a new contact if one does not exist
        if (empty($response->results)) {
            $action = "Creating Contact";

            $contact = new Contact();
            $contact->addEmail($_POST['email']);
            $contact->addList($_POST['list']);
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];

            /*
             * The third parameter of addContact defaults to false, but if this were set to true it would tell Constant
             * Contact that this action is being performed by the contact themselves, and gives the ability to
             * opt contacts back in and trigger Welcome/Change-of-interest emails.
             *
             * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
             */
            $returnContact = $cc->addContact(ACCESS_TOKEN, $contact, false);

            // update the existing contact if address already existed
        } else {
            $action = "Updating Contact";

            $contact = $response->results[0];
            $contact->addList($_POST['list']);
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];

            /*
             * The third parameter of updateContact defaults to false, but if this were set to true it would tell
             * Constant Contact that this action is being performed by the contact themselves, and gives the ability to
             * opt contacts back in and trigger Welcome/Change-of-interest emails.
             *
             * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
             */
            $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, false);
        }

        // catch any exceptions thrown during the process and print the errors to screen
    } catch (CtctException $ex) {
        echo '<span class="label label-important">Error ' . $action . '</span>';
        echo '<div class="container alert-error"><pre class="failure-pre">';
        print_r($ex->getErrors());
        echo '</pre></div>';
        die();
    }
}
?>

autoload.php可以在http://www.thedaileymethod.com/_main_site/wp-content/themes/dailey-method/src/Ctct/autoload.php上找到,这是我在PHP文件中调用的名称,但页面一直在为我而中断。

我的require_once路径是否不正确?

编辑:

加载for代码时,页面500出现错误。当我删除表单代码时,这个错误就消失了,页面加载正常。从PHP错误的角度来看,日志中没有任何内容。

EN

回答 1

Stack Overflow用户

发布于 2015-06-19 15:29:05

使用use use关键字和change删除语句

代码语言:javascript
复制
$cc = new ConstantContact(APIKEY);

代码语言:javascript
复制
$cc = new \Ctct\ConstantContact(APIKEY);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26290053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档