从过去的几天开始,我在http://developer.constantcontact.com/libraries/sample-code.html的 Constant Contact APIs 中寻找解决方案,但找不到。所以,下面是我们的要求。
在我的网站上,我们有捐赠、会员资格等。当用户填写捐赠表格或会员表格或联系表格等时,一旦用户提交表格,我们需要向用户发送确认电子邮件。我们的要求是,我们希望这封电子邮件从 Constant Contact 邮件服务器而不是发送网格或 php 邮件服务器发送。我们已经建立了经常联系的帐户以发送新闻信件。我们需要使用这些详细信息来为单个用户发送确认电子邮件,并将电子邮件 ID 存储在我们的固定联系帐户中。
我们需要有用的 API 以上述过程/方式进行通信。
我们没有找到任何解决方案来为单个捐赠用户发送电子邮件。如何向单个用户和消息发送电子邮件。
目前我们正在使用第三方服务(Send Grid),现在我们想转移到持续联系。我们用 PHP 编程语言开发了这个网站。
请帮助我们以上述程序/方式进行整合。
在这里我附上了文件。当我使用给定的 API 和格式时出现错误
下面是我的简单代码
<?php
require_once 'Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Components\EmailMarketing\Campaign;
use Ctct\Components\EmailMarketing\MessageFooter;
use Ctct\Components\EmailMarketing\Schedule;
use Ctct\Exceptions\CtctException;
// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "xxxxxxxxxxxxxxxxxxxxxxxx");
define("ACCESS_TOKEN", "xxxxxxxx-xxxx-xxxx-xxxx-989939366970");
$date = date('Y-m-d H:i:s');
$cc = new ConstantContact(APIKEY);
try {
$lists = $cc->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
foreach ($ex->getErrors() as $error) {
print_r($error);
}
}
print_r($lists);
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['fname'];
$contact->last_name = $_POST['fname'];
/*
* 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, true);
// update the existing contact if address already existed
} else {
$action = "Updating Contact";
$contact = $response->results[0];
$contact->addList($_POST['list']);
$contact->first_name = $_POST['fname'];
$contact->last_name = $_POST['fname'];
/*
* 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, true);
}
}
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();
}
}
function createCampaign(array $params)
{
$cc = new ConstantContact(APIKEY);
$campaign = new Campaign();
$campaign->name = $params['fname'];
$campaign->subject = "Test Mail Subject";
$campaign->from_name = $params['fname'];
$campaign->from_email = $params['email'];
//$campaign->greeting_string = $params['greeting_string'];
//$campaign->reply_to_email = $params['email'];
$campaign->text_content = $params['content_text'];
$campaign->email_content = $params['content_text'];
$campaign->email_content_format = 'HTML';
// add the selected list or lists to the campaign
$campaign->addList('venky.para@gmail.com');
return $cc->addEmailCampaign(ACCESS_TOKEN, $campaign);
}
function createSchedule($campaignId, $time)
{
$cc = new ConstantContact(APIKEY);
$schedule = new Schedule();
$schedule->scheduled_date = $time;
return $cc->addEmailCampaignSchedule(ACCESS_TOKEN, $campaignId, $schedule);
}
global $wpdb;
if(isset($_POST['submit']))
{
$fname=mysql_real_escape_string($_POST['fname']);
$useremail=mysql_real_escape_string($_POST['email']);
$content=mysql_real_escape_string($_POST['content_text']);
// attempt to create a campaign with the fields submitted, displaying any errors that occur
try {
$campaign = createCampaign($_POST);
} catch (CtctException $ex) {
echo '<span class="label label-important">Error Creating Campaign</span>';
echo '<div class="container alert-error"><pre class="failure-pre">';
print_r($ex->getErrors());
echo '</pre></div>';
die();
}
// attempt to schedule a campaign with the fields submitted, displaying any errors that occur
try {
$schedule = createSchedule($campaign->id,$date);
} catch (CtctException $ex) {
echo '<span class="label label-important">Error Scheduling Campaign</span>';
echo '<div class="container alert-error"><pre class="failure-pre">';
print_r($ex->getErrors());
echo '</pre></div>';
die();
}
}
?>
<script type="text/javascript">
function validtestmail(){
var fname=document.getElementById('fname').value;
var email=document.getElementById('email').value;
var content_text=document.getElementById('content_text').value;
if(fname=='')
{
alert('Enter Name');
document.getElementById('fname').focus();
return false;
}
else if(email=='')
{
alert('Enter Email');
document.getElementById('email').focus();
return false;
}
else if(content_text=='')
{
alert('Enter Content');
document.getElementById('content_text').focus();
return false;
}
}
</script>
<div class="container ">
<div class="row ">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="innerPagesBlock fullWidth">
<div id="primary" class="col-xs-12 col-sm-12 col-md-8 col-lg-8 content-area contactbg">
<div class="myprofileHeading">Change Password </div>
<form class="form-horizontal" role="form" id="member_cp" name="member_cp" action="<?php echo get_bloginfo('home'); ?>/testmail" method="post" onsubmit="return validtestmail();" style="margin-top:30px;">
<!-- Self form start-->
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 formLog">
<span style="font-size:16px; font-weight: bold; color: #FFFFFF;">
<?php
if($msg)
{?>
<div class="<?php echo $class; ?>" role="alert"><?php
echo $msg;
?>
</div><?php
}
?>
</span>
</div>
<div class="form-login formMain">
<label for="inputEmail3" class="col-xs-12 col-sm-4 col-md-4 col-lg-4 control-label">Name:<span>*</span></label>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 formLog">
<input type="text" class="form-control" id="fname" name="fname" placeholder="Name" value="" >
</div>
<label for="inputEmail3" class="col-xs-12 col-sm-4 col-md-4 col-lg-4 control-label">Email: <span>*</span></label>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 formLog">
<input type="text" class="form-control" id="email" name="email" placeholder="Email" value="" >
</div>
<label for="inputEmail3" class="col-xs-12 col-sm-4 col-md-4 col-lg-4 control-label">Content: <span>*</span></label>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 formLog">
<input type="text" class="form-control" id="content_text" name="content_text" placeholder="Content" value="" >
</div>
<div class="col-xs-6 col-sm-2 col-md-2 col-lg-2 formLog">
<button type="submit" class="btn btn-primary btnSubmit" name="submit" id="submit">Submit</button>
</div>
<div class="col-xs-6 col-sm-2 col-md-2 col-lg-2 formLog">
<button type="reset" name="button2" id="button2" class="btn btn-primary btnReset">Reset</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div id="main-content" class="main-content">
<?php
if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
</div><!-- #main-content -->
在这里如何向单个用户发送电子邮件。如何?。可能吗?。请帮我。我从过去两周开始浪费时间。
感谢您