我给他们的支持发了电子邮件,所以我可以自己回答这个问题。他们已经用他们的 API 替换了所有旧方法。您需要将表单的操作设置为您自己的端点(例如signup.php)。
我正在使用 PHP,所以我从https://github.com/campaignmonitor/createsend-php下载了他们的 PHP API 包装器。一个简单的例子是这样的:
require_once 'lib/campaignmonitor/csrest_subscribers.php';
$auth = array(
'api_key' => 'Your API key'
);
$wrap = new CS_REST_Subscribers( 'Your list ID', $auth );
$result = $wrap->add( array(
'EmailAddress' => 'Subscriber email',
'Name' => 'Subscriber name',
'CustomFields' => array(
array(
'Key' => 'Field 1 Key',
'Value' => 'Field Value'
),
array(
'Key' => 'Field 2 Key',
'Value' => 'Field Value'
),
array(
'Key' => 'Multi Option Field 1',
'Value' => 'Option 1'
),
array(
'Key' => 'Multi Option Field 1',
'Value' => 'Option 2'
)
),
'ConsentToTrack' => 'yes',
'Resubscribe' => true
) );
更新:如果你好奇,这是我完整的 PHP:
require_once 'libs/campaignmonitor/csrest_subscribers.php';
$success_message = 'You\'ve been signed up for our email list.';
$error_message_general = 'There was a problem signing you up for the email list. Please try again.';
$error_message_format = 'Please enter a valid email address.';
if ( $_SERVER[ 'REQUEST_METHOD' ] !== 'POST' ) {
renderResponse( true, $error_message_general );
}
else {
$api_key = 'your_api_key_here';
$list_id = 'your_list_id_here';
$email = array_key_exists( 'email', $_POST ) ? $_POST[ 'email' ] : '';
$email = cleanInput( $email );
if ( filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
try {
$auth = array(
'api_key' => $api_key
);
$wrap = new CS_REST_Subscribers( $list_id, $auth );
$result = $wrap->add( array(
'EmailAddress' => $email,
'ConsentToTrack' => 'yes',
'Resubscribe' => true
) );
if ( $result->was_successful() )
renderResponse( false, $success_message );
else
renderResponse( true, $error_message_general );
}
catch ( Exception $e ) {
renderResponse( true, $error_message_general );
}
}
else {
renderResponse( true, $error_message_format );
}
}
function renderResponse( $error, $message ) {
header( 'Content-Type: application/json' );
$result = [
'error' => $error,
'message' => $message
];
echo json_encode( $result );
die();
}
function cleanInput( $data ) {
$data = trim( $data );
$data = stripslashes( $data );
$data = htmlspecialchars( $data );
return $data;
}