This guide uses a newsletter sign-up form to show how to send data from WordPress to CiviCRM and process it there.
WordPress offers several plugins for managing newsletter subscribers directly or passing their details to an email marketing service. However, if you use CiviCRM as your central database for contacts and relationships, it makes sense to manage newsletter subscribers there too. This avoids duplicate records and the need to reconcile contact data across different systems.
Sending newsletters with CiviMail is therefore often a useful first step towards using CiviCRM as an integrated system. For instructions on configuring individual and bulk email delivery, see Sending Emails from CiviCRM.
Table of Contents
- 1. Objective
- 2. The Five Components
- 3. Requirements
- 4. Creating a Form in WordPress
- 5. Connecting WordPress to CiviCRM
- 6. Creating a Newsletter Group
- 7. Configuring Duplicate Matching in CiviCRM
- 8. Processing Newsletter Sign-ups with a Form Processor
- 9. Sending a Double Opt-in Email Automatically
- 10. Testing the Complete Sign-up Process
- 11. Further Documentation
1. Objective
This guide explains how to transfer form submissions from WordPress to CiviCRM for further processing. Although we use newsletter sign-ups as our example, you can apply the same approach to other forms whose submissions need to be processed in CiviCRM.
By the end of the guide, you will have a newsletter form that:
- is embedded in a WordPress page;
- asks only for an email address;
- sends that address to CiviCRM;
- attempts to recognise existing contacts;
- creates a contact if necessary;
- initially treats the subscription as unconfirmed;
- automatically sends a double opt-in email; and
- adds the contact to the newsletter mailing list only after confirmation.
2. The Five Components
We will use Contact Form 7, a popular WordPress plugin that lets you create forms and embed them in posts or pages.
Contact Form 7 is the first of five components working together:
-
Contact Form 7 displays the form.
Visitors enter their email address on the WordPress page and submit the form. -
A WordPress hook sends the data to CiviCRM.
A short piece of PHP code runs when the form is submitted and passes the email address to CiviCRM. -
A Form Processor in CiviCRM determines what happens next.
The Form Processor receives the submitted email address and performs the configured actions. -
The Extended Contact Matcher in CiviCRM checks for an existing contact.
The Extended Contact Matcher (XCM) searches for a contact with the same email address. It creates a new contact only if it cannot find a suitable match. -
CiviCRM handles double opt-in.
CiviCRM sends an email containing a confirmation link. The subscription takes effect, and the contact becomes a full member of the newsletter group, only after they follow that link.
3. Requirements
You will need:
- administrator access to your WordPress website; and
- administrator access to a CiviCRM instance.
If you do not yet have CiviCRM, you can get started with CiviCRM and try it free of charge.
4. Creating a Form in WordPress
4.1 Installing Contact Form 7
Open your WordPress administration area and go to Plugins → Add New Plugin. Search for Contact Form 7, install it and activate it.
Then open Contact → Add New to create a contact form.
4.2 Creating the Form
For example, create this form:
``text
[submit "Subscribe to the newsletter"]
``
The field name email is important: it must match the system name of the input field you will define later in the CiviCRM Form Processor.
Next, open the Messages tab. Here you can change the success message displayed after a submission.
For example:
Thank you. We have sent you an email with a confirmation link. Your subscription will take effect only after you follow that link.
Then open the Additional Settings tab.
If you do not want Contact Form 7 to send a separate email notification, disable the plugin's normal mail delivery by entering:
skip_mail: on
CiviCRM, rather than Contact Form 7, will send the double opt-in confirmation email.
4.3 Embedding the Form in a WordPress Page
After you save the form, Contact Form 7 displays a shortcode, for example:
[contact-form-7 id="1234" title="Newsletteranmeldung"]
Insert this shortcode wherever you want the form to appear in a WordPress post or page.
The form will now be displayed at that location. However, the email address entered into it is not yet sent to CiviCRM. To make that happen, we need to add a small amount of PHP code to WordPress.
5. Connecting WordPress to CiviCRM
Contact Form 7 provides a WordPress hook called wpcf7_before_send_mail.
A hook is a point at which custom PHP code can join a plugin's processing workflow.
The wpcf7_before_send_mail hook runs after the form has been validated but before the final success response. This allows our code to:
- read the submitted email address;
- send it to CiviCRM;
- respond to technical errors; and
- prevent the form from reporting a successful sign-up if an error occurs.
5.1 Creating a Contact for the Integration
The PHP code we will add to WordPress requires CiviCRM credentials. To manage these securely, we will create a dedicated technical user in CiviCRM. Its sole purpose is to submit data from WordPress. This lets us restrict its permissions and disable or change access without affecting anyone's personal account.
In CiviCRM, go to Contacts → New Individual and create a contact with details such as:
- Last name:
formprocessor_api_kontakt - Email address: an address used exclusively for the integration
- Contact type: Individual
This contact does not represent a real person. It provides an identifiable record for the integration's permissions and API key.
In CiviCRM, API keys are associated with a contact or the user account linked to that contact. The linked user's permissions determine which actions the integration may perform.
5.2 Creating a Dedicated User Role
Go to Administration → Users and Permissions → User Roles and create a role with a distinctive name, for example:
formprocessor_api_rolle
Grant this role only the permissions required by the integration:
- CiviCRM: administer CiviCRM
- CiviCRM: edit all contacts
For security reasons, do not assign the integration a general administrator role.
5.3 Creating a User Account
Next, open Administration → Users and Permissions → User Accounts. Select Add User and enter details such as:
- Username:
formprocessor_api_benutzer - Email address: the address stored against the technical contact
- Linked contact:
formprocessor_api_kontakt - Role:
formprocessor_api_rolle
You must explicitly link the user account to the contact you created earlier. Only then can that contact's API key be used to make requests with the user's permissions.
Give this account a long, randomly generated password, even if you do not intend to use it for normal sign-ins.
5.4 Generating the Site Key and API Key
The PHP code will need two credentials:
- your CiviCRM instance's site key; and
- the technical user's API key.
The API Key extension is already installed in polbeo polishub. It lets you generate and view API keys and the site key from a contact record.
Open the formprocessor_api_kontakt contact. The contact view includes an API Key tab where you can:
- generate a new API key;
- view or change an existing API key; and
- view the CiviCRM instance's site key.
Use a long, randomly generated API key dedicated to this integration. Do not reuse it for other services.
Store both the site key and API key in a password manager. They provide authenticated access to your CiviCRM instance and should not appear in unprotected documentation or emails.
5.5 Setting Up the WordPress Hook
We can now use the wpcf7_before_send_mail hook provided by Contact Form 7.
One of the simplest ways to add PHP code to WordPress is to install the Code Snippets plugin.
In the WordPress administration area, go to Plugins → Add New Plugin. Search for Code Snippets, install it and activate it.
Then open Snippets → Add New.
Developers call short, self-contained pieces of PHP code snippets. Our snippet will run when someone submits the Contact Form 7 form we created earlier. It reads the email address and uses the CiviCRM API to call the Form Processor.
5.6 Adding the PHP Snippet
Add the following PHP code.
If you have used PHP before, note that you do not need the usual opening <?php line here.
The code performs four tasks:
- It runs only for the intended newsletter form.
- It reads the email address entered by the visitor.
- It passes the address to the CiviCRM Form Processor.
- It displays an error message if CiviCRM cannot process the request.
Copy the following code into Code Snippets. You will need to make the changes described immediately below it.
add_action(
'wpcf7_before_send_mail',
'newsletter_an_civicrm_senden',
10,
3
);
function newsletter_an_civicrm_senden(
$contact_form,
&$abort,
$submission
) {
// Process this Contact Form 7 form only.
if ((int) $contact_form->id() !== 1234) {
return;
}
// Read and validate the email address.
$data = $submission->get_posted_data();
$email = sanitize_email($data['email'] ?? '');
if (!is_email($email)) {
$abort = true;
$submission->set_response(
'Please enter a valid email address.'
);
return;
}
// Send the email address to the CiviCRM Form Processor.
$response = wp_remote_post(
'https://crm.example.org/civicrm/ajax/rest',
[
'timeout' => 15,
'body' => [
'entity' => 'FormProcessor',
'action' => 'newsletter_signup',
'json' => 1,
'key' => 'DEIN_SITE_KEY',
'api_key' => 'DEIN_API_KEY',
'email' => $email,
],
]
);
// Check the response from CiviCRM.
if (is_wp_error($response)) {
$error = true;
} else {
$status = wp_remote_retrieve_response_code($response);
$result = json_decode(
wp_remote_retrieve_body($response),
true
);
$error =
$status < 200
|| $status >= 300
|| !is_array($result)
|| !empty($result['is_error']);
}
// Do not report a successful sign-up if processing fails.
if ($error) {
$abort = true;
$submission->set_response(
'Your subscription could not be processed because of a technical error. '
. 'Please try again later.'
);
}
}
Change the following values in the code:
1234: the ID of your Contact Form 7 formhttps://crm.example.org: the address of your CiviCRM instancenewsletter_signup: the system name of your Form ProcessorDEIN_SITE_KEY: your CiviCRM instance's site keyDEIN_API_KEY: the technical user's API key
You can find the Contact Form 7 form ID in the shortcode displayed after saving the form.
Later in this guide, we will create the Form Processor with the system name newsletter_signup.
The CiviCRM credentials you created earlier are now stored on the WordPress server, rather than being sent to visitors' browsers. If CiviCRM cannot process the submission, the code stops the process. Contact Form 7 then displays the error message defined in the snippet instead of its normal success message.
Activate the snippet once you have updated the values.
The request will not work yet because the Form Processor it calls has not been created in CiviCRM. We will do that shortly.
The WordPress side of the connection is now ready.
5.7 Protecting the Form Against Spam
The double opt-in process we will configure in CiviCRM prevents someone else's email address from being added to your newsletter mailing list without confirmation. It does not, however, stop automated submissions from creating unwanted contact records in CiviCRM or triggering large numbers of unwanted confirmation emails.
You should therefore protect the WordPress form against spam as well. Cloudflare Turnstile is one option supported by Contact Form 7.
In WordPress, open Contact → Integration and configure Turnstile using a site key and secret key issued by Cloudflare. Contact Form 7 will then automatically protect forms created with the plugin. You would not normally need to change the newsletter form itself.
The spam check takes place before our PHP snippet sends the email address to CiviCRM. Submissions identified as spam therefore never reach the CiviCRM Form Processor.
Alternatively, or in addition, you can integrate Contact Form 7 with Akismet. Remember that this involves sending form data to an external service for assessment, so you must account for its use in your privacy notice.
If you still receive many repeated submissions, consider limiting how often a single IP address can submit the form within a given period. Depending on your setup, you can apply such rate limiting through your hosting provider, web server or an upstream firewall.
6. Creating a Newsletter Group
Before contacts can subscribe to your newsletter, you need a mailing list. CiviCRM uses groups for this purpose. You can create as many groups as you need, so the approach described here can also be used for other mailing lists or groups.
In CiviCRM, open Contacts → Manage Groups → Add Group. Create a group named, for example, Newsletter.
Set:
- Group type to Mailing List; and
- Visibility to Public Pages.
Marking the group as a mailing list makes it available to CiviMail. Public visibility is required for the sign-up process used here: only groups with Public Pages visibility can trigger the double opt-in confirmation email.
Note the group's numeric ID. You can find it, for example, in the URL of the group editing page. You will need this ID for the double opt-in request later.
7. Configuring Duplicate Matching in CiviCRM
Before creating the Form Processor, decide how CiviCRM should search for an existing contact. We will use the Extended Contact Matcher (XCM). It looks for suitable contacts using CiviCRM's duplicate matching rules and creates a new one only if no match is found.
Open Administration → System Settings → Extended Contact Matcher.
There is no button for creating a profile from scratch on the overview page. Instead, make a copy of the existing default profile by selecting copy on the default row. Then enter, for example:
- Profile ID:
newsletter_abonnent - Profile name: Newsletter sign-up via WordPress
The profile ID must not contain spaces.
The configuration page contains many settings, but our simple newsletter form needs only a few changes.
Under General Settings, set Primary Phone Type to Phone and Default Website Type to Main Address. We set these values only because they are required by the system. They do not otherwise affect this example, since we supply neither phone nor website data for matching. The important setting is When multiple matches are found, use:. You can choose the oldest contact, the newest contact or none of the matching contacts. The best option depends on your database. If several people in your organisation sometimes share an email address, automatically selecting one of them may associate the subscription with the wrong person.
Leave Update Options empty.
Under the matching rules, choose a rule for Rule #1 that finds contacts by any stored email address, such as Email only (any email). Set all other rules to None. Otherwise, XCM may attempt to use rules for which the form supplies no data.
If the email matching rule you need is not listed, go to Contacts → Find and Merge Duplicate Contacts and create a suitable rule for individuals based on email address. Then return to the XCM configuration and select it.
No additional actions are needed for this use case under:
- Identified Contacts;
- Newly Created Contacts;
- Duplicate Activity; or
- Difference Handling.
The Form Processor, not XCM, will handle the newsletter group subscription.
Save the profile.
With duplicate matching configured, a repeat sign-up using the same email address should be linked to the existing contact wherever possible, rather than creating a new contact each time.
8. Processing Newsletter Sign-ups with a Form Processor
Now that the WordPress form, newsletter group and duplicate matching rules are ready, you can create the Form Processor in CiviCRM.
The Form Processor receives the email address submitted from WordPress and carries out the configured actions.
8.1 Creating a Form Processor
In CiviCRM, open Administration → Automation → Form Processors and select Add Form Processor.
Use settings such as:
- Title: Newsletter sign-up via WordPress
- System name:
newsletter_signup - Status: enabled
- Permission: CiviCRM: access CiviCRM backend and API
The system name must not contain spaces. It is used as the name of the API action.
The WordPress snippet we added earlier calls the Form Processor using this value:
newsletter_signup
If you use a different system name, update the WordPress snippet to match.
8.2 Defining an Input Field
Under Inputs, add an input field to the Form Processor.
For example, use:
- Type: Short text
- Title: Email
- System name:
email - Required: yes
The system name is essential. Both the WordPress form and the PHP snippet send the email address under this exact name:
email
If the system names differ, the Form Processor cannot use the submitted value.
8.3 Finding or Creating a Contact with XCM
Under Actions, add an action of type Extended Contact Matcher (XCM) to call the matcher.
- Title: Create contact
- XCM profile: Newsletter subscriber
- Default Contact Type: Individual
- Email: Input:
email
You will find Email under Parameter Mapping. This is a long list of fields, but because our form supplies only an email address, we need to map only that one field.
Save the action configuration.
9. Sending a Double Opt-in Email Automatically
Next, configure the subscription itself.
The contact should not become a full member of the newsletter group immediately. Instead, CiviCRM should first send a confirmation email.
Group membership becomes active only after the recipient follows the link in that email.
9.1 Triggering Double Opt-in
Add the subscription action to the Form Processor.
Use:
- Action type: Mailing Event: Subscribe to mailing list
- Title: Send DOI email
- Subscribe to mailing list: Newsletter
- subscribe e-mail: Input:
email - CiviCRM ID: Action: Create contact: CiviCRM ID
Do not simply use the Add Contact to Group action here.
That would add the contact as a full group member immediately, bypassing the confirmation step.
By contrast, Mailing Event: Subscribe to mailing list starts CiviCRM's subscription process:
- The contact is not yet fully subscribed to the newsletter group; their membership status is pending.
- CiviCRM sends an email containing a confirmation link.
- The recipient follows the link.
- CiviCRM activates the group membership.
9.2 Testing the Form Processor in CiviCRM
Test the Form Processor using its Try out tab.
Enter a working test email address and run the Form Processor.
Then check:
- Did it find an existing contact or create a new individual contact?
- Can you see a pending group subscription against the contact?
- Was the double opt-in email sent?
- Does the confirmation link complete the subscription successfully?
- After confirmation, is the contact a full member of the newsletter group?
Test the Form Processor within CiviCRM before testing it through WordPress.
10. Testing the Complete Sign-up Process
Once the Form Processor works within CiviCRM, test the entire process through the WordPress form.
Use a new, working email address.
Do not stop at checking whether Contact Form 7 displays a success message. Follow the submission through every stage:
- You can submit the form.
- The email address is transferred correctly.
- XCM finds an existing contact or creates a new one if necessary.
- Repeated subscriptions do not cause XCM to create unnecessary duplicate contacts.
- The double opt-in email arrives.
- The confirmation link works.
- Group membership becomes active only after confirmation.
- Subscribing again with the same address does not create an unnecessary extra contact.
You should also test how the integration handles a technical failure.
For example, temporarily enter either:
- an incorrect CiviCRM address; or
- an invalid API key
in the WordPress snippet.
In this case, the form must not report a successful subscription. Instead, it should display the error message defined in the snippet:
Your subscription could not be processed because of a technical error. Please try again later.
This ensures that visitors see a success message only when CiviCRM has actually received and processed their request.
Don't have CiviCRM yet? Get started and try it free for four weeks.
11. Further Documentation
The following chapters of the official CiviCRM documentation cover the features and extensions used for newsletter sign-ups via WordPress.
CiviCRM User Guide
-
Set-up – Relevant to sections 6 and 9: Explains how to configure mailing lists, accept subscriptions through public forms and run the double opt-in process, including confirmation emails and initially pending group memberships.
-
Deduping and Merging – Relevant to section 7: Describes CiviCRM's duplicate matching rules, which help determine whether a contact already exists.
CiviCRM System Administrator Guide
- API Keys – Relevant to sections 5.1–5.4: Explains how API keys are issued and managed and how they relate to contacts and user permissions.
CiviCRM Developer Guide
- APIv3 REST – Relevant to sections 5.5 and 5.6: Documents the REST endpoint used by WordPress to call the Form Processor and the supported authentication methods.
CiviCRM Extension Documentation
-
Form Processor – Sign Up for Newsletter (WordPress) – Relevant to sections 4, 5, 8 and 9: An official example of newsletter sign-up through a separately hosted WordPress website. It also uses Contact Form 7 and Form Processor, but connects the systems and processes subscriptions differently.
-
Form Processor – Basic Concept – Relevant to sections 8 and 9.2: Describes how Form Processor works, how to define input fields and actions, and how to test a Form Processor within CiviCRM.
-
Extended Contact Matcher – Configuration – Relevant to sections 7 and 8.3: Explains how to configure the Extended Contact Matcher (XCM), including duplicate matching rules and the handling of existing contacts.
How This Guide Differs
The official WordPress example for Form Processor uses an additional integration extension and adds contacts directly to a newsletter group. Our approach instead uses a WordPress hook to send data, the Extended Contact Matcher to check for duplicates, and CiviCRM's double opt-in process. As a result, contacts become full members of the newsletter group only after confirming their email address.
A Note on the API
The CiviCRM developer documentation now marks APIv3 as deprecated and recommends APIv4 for new developments. The integration described here currently uses the APIv3 REST endpoint.
Documentation last reviewed: 25 October 2026. The linked chapters were consulted on that date. Links point to the latest available English-language documentation ("latest").