is it possible to return true or false for email check?

SOLVED
Go to solution
Regular Participant

is it possible to return true or false for email check?

I'm trying to wrap my head around the CC api in relation to checking an email address against a list, but I cannot for the life of me figure it out. Is it possible to return a simple true or false when submitting an email address in a form?

 

I've read this: http://community.constantcontact.com/t5/Documentation/Searching-for-a-Contact-by-Email-Address/ba-p/... but it has no actual implementation examples. Here's the code I've been trying, but it is not working.

 

include_once('cc_class.php');

 

$ccContactOBJ = new CC_Contact("basic", $cckey, $ccuser, $ccpass);


//if we have post fields means that the form have been submitted.
if(($_SERVER['REQUEST_METHOD']=="POST") && !empty($_REQUEST['member-submit'])) {
$contact = $ccContactOBJ->getSubscribers(urlencode($_POST['MemberEmail']));
if (empty($contact['items'])) {
$message = 'You have been added to our database.';
echo $message;
}
else {
$message = 'You are already listed in our database';
echo $message;
}
}

1 ACCEPTED SOLUTION

Thank you for the file,

 

I just reviewed it and found the login variable missing an 'e' in the name of the account.  After adding that in, I was able to make successful requests to our API.  

 

Please confirm this as a solution after you've tested.

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot

View solution in original post

15 REPLIES 15
Employee

Hey Kevin,

 

The class you are using has a public function called subscriberExists which will return an ID if successful or false if unsuccessful.  

 

$response = $ConstantContact->subscriberExists($emailAddress);
if ($response == false)
{
  //Contact does not exist
echo "Invalid Email Address"; } else { //Contact does exist
echo $response; }

 Hope this helps.  Just let us know.

Thanks,

Andrew Weber
Associate Product Manager for EventSpot
Regular Participant

Thanks, but that returns an error. Here's my code now:

 

$ccContactOBJ = new CC_Contact("basic", $cckey, $ccuser, $ccpass);


if(($_SERVER['REQUEST_METHOD']=="POST") && !empty($_REQUEST['member-submit'])) {
$contact = $ccContactOBJ->subscriberExists(urlencode($_POST['MemberEmail']));
echo $contact;

}

 

What I get back regardless of input is "The requested URL returned error: 401"

Hey Kevin,

 

401 means the credentials you are passing are not correct.  You can read more about that here: 401

 

The file you are including is part of a larger project that auto generates a form for people to use to have a custom signup form added to their website.  If you are not using this and are only using the file to create your own signup form, you may want to use another wrapper which is better suited for that type of usage.  You can find this wrapper here: wrapper

 

Because that file you are using is part of a bigger project, it also requires another file called config.php.  Since you got a 401 error and not another error code, it appears this config.php file does exisit on your server but perhaps the credentials stored in that file are not correct and thus why you are getting a 401.  

 

Please double check that file.

If all checks out, please either DM me that information so I may test using your credentials or you can email

 

webservices AT constantcontact DOT com

 

The above code has been tested and works with the mentioned files.  I'm sure we can figure out a solution for you.

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot
Regular Participant

I went ahead and started using the different wrapper (despite the fact that it was working fine for adding contacts).

 

Now I can't even get my page to load. I mean, it's completely blank page. Which means some kind of error. I really could use some help.

Regular Participant

I went back and looked at my original cc_class.php file. You're incorrect--it does not reference a config.php file, and it contains login credentials inside the CC_Utility class.

 

Like this:

var $login = '***********'; //Username for your account
var $password = '*************'; //Password for your account
var $apikey = '*********************************'; // API Key for your account.

 

So with that, I took a look at my file setup:

 

include_once('cc_class.php'); //Call the class.

 

$ConstantContact = new CC_Contact(); //Instantiate new instance

 

$emailAddress = str_replace ( array("\n"), array("<br>"),trim($_REQUEST['MemberEmail'])); //Grab the email address from the form submission

 

if(($_SERVER['REQUEST_METHOD']=="POST") && !empty($_REQUEST['member-submit'])) { //double check the form has actually been submitted and that it's not empty

 

$response = $ConstantContact->subscriberExists($emailAddress); //put the subscriber ID into $response
if ($response == false) {
echo "Failure";
} else {
echo "Success";
}

 

 

And this all still results in a 401. WTF??!

Sorry Kevin,

 

cc_class.php resides in 2 wrappers and I thought you were using another wrapper.  I will test with the other wrapper and get back to you.  In the mean time, can you DM me the username you are using so I can check the logs on our servers?

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot

Hey Kevin,

 

Just tried the other cc_class file and it is working for me after hard coding credentials into the file.  Send me your Username so I can check logs and dig deeper as to why it is not working for you.

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot

Thank you Kevin,

 

We have received the requested information and will begin testing with those credentials and checking logs for possible solutions.

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot

Hey Kevin,

 

Using your credentials I was able to search by emailAddress.
I noticed you are using a variable name $username. The default cc_class.php file uses $login.  
Did you change anything in the file itself?

Could you attach it here so I can see its contents?

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot
Regular Participant

I wasn't copying from the file directly. In the file, the variable name is $login. I will attach it for you.

Regular Participant

Can I attach a php file here? Or do I need to paste the file contents?

Hey Kevin,

 

You can attach it to the email you should have received when you emailed webservices or just email it directly to me:

aweber AT constantcontact DOT com

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot
Regular Participant

Thanks. I've just emailed you the file directly.

Thank you for the file,

 

I just reviewed it and found the login variable missing an 'e' in the name of the account.  After adding that in, I was able to make successful requests to our API.  

 

Please confirm this as a solution after you've tested.

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot

View solution in original post

Regular Participant

Hi Andrew,

Good catch. It looks like I was using a different (correct) $login for the section where I was adding contacts. Which is why I was confused about the 401. Thank you for reviewing this.

 

I do have another issue related to this, but I'll open up a new thread for it.

Developer Portal

View API documentation, code samples, get your API key.

Visit Page