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
Log in to EspoCRM as an admin.
Go to Administration → Lead Capture
Click Create Web-to-Lead
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
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
Navigate to your WordPress install root (usually
/htdocsor/public_html)Create a folder named:
/api/
Inside it, create a new file:
espocrm-lead-handler.php
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’; // 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.
Go to:
/wp-content/plugins/
Create a file:
cf7-to-espocrm.php
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’, [
‘method’ => ‘POST’,
‘timeout’ => 15,
‘headers’ => [‘Content-Type’ => ‘application/x-www-form-urlencoded’],
‘body’ => $postData
]);
});
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.
