Add opt in check box to wordpress contact form


Add opt in check box to wordpress contact form

Hi, I have a contact form on my wordpress site and I would like to add an opt in box so that the user can choose to be added to the newsletter subscription if they wish when they send the contact form.


<input name="emailUpdates" type="checkbox" value="Yes" /> 
<label>Register for exclusive offers and promotions?</label>


I am having problems finding info on how to integrate this.


Here is my code. It's a basic wp_mail form.


$validation_message = "";

if( isset($_POST['submit']) ){

$passes = true;
$validation_template = "<div class='alert %s'><i class='fa %s'></i> %s</div>";

// Verify nonce before proceeding
if( !isset( $_POST['sc_contact_form_nonce'] ) || !wp_verify_nonce( $_POST['sc_contact_form_nonce'], basename( __FILE__ ) ) ){
$validation_message = sprintf($validation_template, 'alert-error', 'fa-times-circle', 'Sorry Something went wrong, please try again.');
$passes = false;

if( !$_POST['form_fname'] || !$_POST['form_lname'] || !$_POST['form_email'] || !$_POST['form_message'] ){
$validation_message = sprintf($validation_template, 'alert-error', 'fa-times-circle', 'Please fill in all fields.');
$passes = false;
} elseif( !preg_match('/(^.*@.*$)/', $_POST['form_email']) ){
$validation_message = sprintf($validation_template, 'alert-error', 'fa-times-circle', 'Please provide a valid email address.');
$passes = false;

if( $passes ) {
//Build Message

$message = 'First Name: '.$_POST['form_fname']."\n";
$message .= 'Last Name: '.$_POST['form_lname']."\n";
$message .= 'Email: '.$_POST['form_email']."\n";
$message .= 'Development of interest: '.$_POST['form_devname']."\n";
$message .= "Message:\n" .$_POST['form_message'];

$validation_message = sprintf($validation_template, 'alert-success', 'fa-check-circle', 'Thank you for your enquiry. We will be in touch as soon as possible.');

//add_filter( 'wp_mail_content_type', 'set_html_content_type' );
$headers = 'From: '.$_POST['form_fname'].' '.$_POST['form_lname'].' <'.$_POST['form_email'].'>' . "\r\n";
wp_mail( "", "Website Enquiry", $message, $headers, $attachments );


} else {
$passes = false;

<div class="col-sm-12 row">
<div id="enquiry"></div>

    <form id="contact-form" action="#enquiry" class="row" method="POST" <?php echo $passes ? 'style="display:none;"' : '' ; ?>>
    <?php wp_nonce_field( basename( __FILE__ ), 'sc_contact_form_nonce' ); ?>
    <div class="form-group col-sm-6">
    <input id="contact_fname" class="form-control" type="text" name="form_fname" required placeholder="First Name" value="<?php echo isset($_POST['form_fname']) ? $_POST['form_fname'] : '' ; ?>" />
    <div class="form-group col-sm-6">
    <input id="contact_lname" class="form-control" type="text" name="form_lname" required placeholder="Last Name" value="<?php echo isset($_POST['form_lname']) ? $_POST['form_lname'] : '' ; ?>" />
    <div class="form-group col-sm-12">
    <input id="contact_email" class="form-control" type="text" name="form_email" placeholder="Your Email Address" value="<?php echo isset($_POST['form_email']) ? $_POST['form_email'] : '' ; ?>" />
    <input id="contact_devname" class="form-control col-sm-12" type="hidden" name="form_devname" placeholder="" value="<?php single_post_title();?>" />
    <div class="form-group col-sm-12">
        <textarea id="contact_message" class="form-control" name="form_message" placeholder="Your Enquiry" rows="8"><?php echo isset($_POST['form_message']) ? $_POST['form_message'] : '' ; ?></textarea>
    <div class="form-group col-sm-12">
    <input name="emailUpdates" type="checkbox" value="Yes" /> 
    <label>Register for exclusive offers and promotions?</label>
    <div class="col-sm-12">
    <button class="btn" name="submit">Send Enquiry</button>



It is absolutely possible to do this by adding some code to your PHP that will send the contact to your Constant Contact account by using our embeddable signup form system.


To get up and running with this, you'll need to start by creating a form in your account and getting the embed code. When you create the form, be sure to choose the list you wish to place your contacts on. Once you've got the embed code, you'll want to find your CA ID. You can find information about all of this here:

Creating your form:

Get your Embed code and find the CA ID:


 Next, you'll want to find the List ID in the embed code. You can find it by looking for this code:



 <input data-id="list:input" type="hidden" name="list" value="LISTID">



Once you have both the CA and List ID, you can use this sample PHP code to add contacts to your account:


$url = "";
$ca = "YOUR_CA_HERE";
$email = "";
$first_name = "First Name";
$last_name = "Last Name";
$lists[] = "LIST_ID_1";
$lists[] = "LIST_ID_2";
$lists[] = "LIST_ID_3";

$post_vars = "ca=" . $ca . "&email=" . $email . "&first_name=" . $first_name . "&last_name=" . $last_name;
foreach ($lists as $list) {
	$post_vars .= "&list=".$list;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_vars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$success = $http_code == 200 ? true : false;


Once you've got this code successfully creating contacts in your Constant Contact account, it should be pretty straightforward to adapt it into your form. If you have any questions, please let me know!



Elijah G.
API Support Engineer
Occasional Participant

This is crazy. We way a lot of money for Constant Contact. Why can't you all add a check box option to the forms? It would be very helpful to many, i'm sure.

Hi @MeredithP9,


This post is from 2016 and is related to a customer that created their own form for WordPress. Did you create your own form or are you using the Constant Contact form created by Constant Contact?


If you are using the plugin that can be installed from then I highly suggest you make a post on the forums under the support section on that page. The developer for that plugin monitors those forums for suggestions and feedback there. I will also be happy to send along your feedback, but those forums get the information to the developer directly.

Jimmy D.
Tier II API Support Engineer

Hi, I see that the CA id is no longer used and this method was from 2016. Is there an updated version of this php code or a new way to accomplish this?


I'd like to integrate an opt-in checkbox into our existing contact forms on our Wordpress website to capture those email addresses in Constant Contact automatically.


Please advise. Thank you!

Hi @JohnF25,


The forms provided by Constant Contact work with a single contact list. If you are looking to use multiple contact lists and use a check box system you will either want to use a third party sign-up form, or you will want to create your own sign-up form using our API.


For a WordPress site I know there are a few different plugins that work with Constant Contact that are created by third party companies and they offer check box forms however; I do not know the exact names of the plugins.

Jimmy D.
Tier II API Support Engineer
Developer Portal

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

Visit Page