Refer a business, earn rewards
Mon–Fri · 9am–5pm (24/7 Support for Managed Clients)
Flat digital illustration showing the integration process between WordPress Contact Form 7 and EspoCRM using a secure backend PHP handler

If you’re using Contact Form 7 to collect leads on your WordPress site and want to send those submissions directly into EspoCRM, this guide walks you through a secure and professional integration using a custom PHP handler.

✅ No third-party plugins required
✅ No exposure of your API keys
✅ Clean and secure setup
✅ Works even on shared hosting environments


What You’ll Need

  • A WordPress site with Contact Form 7 installed

  • Access to your WordPress file system (via FTP, File Manager, or SSH)

  • Admin access to EspoCRM

  • A bit of time and a working coffee ☕


Step 1: Create a Web-to-Lead Entry in EspoCRM

  1. Log in to EspoCRM as an admin.

  2. Go to Administration → Lead Capture

  3. Click Create Web-to-Lead

  4. Fill out the form:

    • Name: Website Contact Form

    • Payload Fields:

      • Name

      • Email

      • Phone

      • Account Name

      • Description

    • Set Status to Active

    • Assign a Team and (optionally) a Target List

  5. Save and copy the generated URL (e.g. https://your-crm.com/api/v1/LeadCapture/xxxxxxxxxxxxxxxx)


Step 2: Add a PHP Handler on Your Server

  1. Navigate to your WordPress install root (usually /htdocs or /public_html)

  2. Create a folder named:

/api/
  1. Inside it, create a new file:

 
espocrm-lead-handler.php
  1. Paste this code inside (use your LeadCapture URL):

 
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ($_SERVER[‘REQUEST_METHOD’] !== ‘POST’) {
http_response_code(405);
exit(‘Method Not Allowed’);
}

$leadData = [
‘name’ => htmlspecialchars($_POST[‘text-967’] ?? ‘Website Visitor’, ENT_QUOTES),
’email’ => filter_var($_POST[’email-191′] ?? ‘noemail@noreply.com’, FILTER_SANITIZE_EMAIL),
‘phone’ => htmlspecialchars($_POST[‘text-968’] ?? ‘N/A’, ENT_QUOTES),
‘accountName’ => htmlspecialchars($_POST[‘text-969’] ?? ‘Unspecified’, ENT_QUOTES),
‘description’ => htmlspecialchars($_POST[‘textarea-579’] ?? ‘No message provided.’, ENT_QUOTES),
‘source’ => ‘Web Site’
];

$crmUrl = https://your-crm.com/api/v1/LeadCapture/xxxxxxxxxxxxxxxx&#8217;; // Replace with yours

$ch = curl_init($crmUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [“Content-Type: application/json”]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($leadData));

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo “Lead sent to EspoCRM. Status: $httpCode“;

⚠️ Make sure this script is accessible (e.g. https://yourdomain.com/api/espocrm-lead-handler.php)


Step 3: Create a Custom Plugin to Post Form Data

Instead of editing your theme, use a custom plugin for long-term stability.

  1. Go to:

 
/wp-content/plugins/
  1. Create a file:

 
cf7-to-espocrm.php
  1. Paste this code:

 
<?php
/*
Plugin Name: CF7 to EspoCRM Integration
Description: Sends CF7 submissions to EspoCRM
Version: 1.0
*/
add_action(‘wpcf7_mail_sent’, function () {
$submission = WPCF7_Submission::get_instance();
if (!$submission) return;

$data = $submission->get_posted_data();

$postData = [
‘text-967’ => $data[‘text-967’] ?? ,
’email-191′ => $data[’email-191′] ?? ,
‘text-968’ => $data[‘text-968’] ?? ,
‘text-969’ => $data[‘text-969’] ?? ,
‘textarea-579’ => $data[‘textarea-579’] ??
];

wp_remote_post(https://yourdomain.com/api/espocrm-lead-handler.php&#8217;, [
‘method’ => ‘POST’,
‘timeout’ => 15,
‘headers’ => [‘Content-Type’ => ‘application/x-www-form-urlencoded’],
‘body’ => $postData
]);
});

  1. Log into WordPress → Plugins and activate CF7 to EspoCRM Integration


Step 4: Use Matching Fields in Your Contact Form 7 Form

Here’s a sample Contact Form 7 configuration:

[text* text-967 placeholder "Your Name"]
[email* email-191 placeholder "Your Email"]
[text text-968 placeholder "Your Phone Number"]
[text text-969 placeholder "Your Company Name"]
[textarea textarea-579 placeholder "Your Message"]
[submit "Send Request"]

Save and publish the form on your contact page.


Step 5: Test It!

  • Visit your contact page

  • Submit a test entry

  • You should:

    • ✅ Receive the submission email (CF7 default)

    • ✅ See a new lead created in EspoCRM

    • ✅ Name, email, phone, and message included


Security & Cleanup Tips

  • ✅Logs and debug code were removed from production

  • ❌ Don’t expose your handler URL or EspoCRM API ID publicly

  • 🔐 Want to add more protection? Use an authorization token or origin check

  • 📦 Optional: Package the handler + plugin into a .zip for reuse


Final Thoughts

This simple, secure approach gives you full control of your lead capture process without relying on third-party integrations.

If you’d like help building this into a reusable plugin, adding fallback error handling, or syncing EspoCRM data back into WordPress, drop a message below.

Discover more from No Limit Systems

Subscribe now to keep reading and get access to the full archive.

Continue reading