Отправка почты с использованием постоянного почтового сервера вместо php mail

В последние несколько дней я ищу решение в API-интерфейсах Constant Contact по адресу http://developer.constantcontact.com/libraries/sample-code.html,, но не смог его найти. Итак, ниже наше требование.

На моем веб-сайте есть пожертвования, членство и т. Д. Когда пользователь заполняет форму пожертвования, форму членства или форму контакта и т. Д., Как только пользователь отправляет форму, нам необходимо отправить подтверждение по электронной почте пользователю. Наше требование заключается в том, что мы хотим, чтобы это письмо было отправлено. из Контакта Контактный почтовый сервер вместо почтовой сетки или php почтового сервера. У нас уже есть постоянный контакт для отправки новостных писем. мы должны использовать эти данные для отправки электронных писем с подтверждением для одного пользователя и сохранять идентификатор электронной почты в нашей постоянной контактной учетной записи.

Нам нужны полезные 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 -->

Вот как отправить письмо одному пользователю. Как?. Является ли это возможным?. Пожалуйста, помогите мне. Мое время тратится с последних 2 недель.

Благодарю вас

0

Решение

Вам нужно привести $ _POST [‘list’] как строку. Это может быть пост в виде целого числа.

Меняем это:

$contact->addList($_POST['list']);

к этому:

$contact->addList( (string)$_POST['list'] );

вероятно, сделал бы это.

0

Другие решения

Других решений пока нет …