← Back to Blog

Legacy to Modern: Integrating WhatsApp API using PHP cURL

By 5MinutesAPI Engineering

Upgrading Legacy Systems

Many robust enterprise systems, CRMs, and e-commerce platforms (like older Magento or custom WordPress plugins) are built on PHP. Migrating entirely to a modern Node.js or Go stack isn't always feasible. The good news is that you don't have to rebuild your backend to get modern communication tools.

5MinutesAPI exposes a highly standardized REST endpoint that works flawlessly with PHP's native cURL functions.

The cURL Implementation

To send a WhatsApp message, your PHP script simply needs to construct a JSON payload and dispatch it to our engine. Ensure your PHP environment has the cURL extension enabled.



 "971501234567",
"whatsapp_template" => "invoice_generated_alert"
]);

// Initialize cURL session
$ch = curl_init($api_url);

// Set cURL options
curl_setopt(ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $api_key,
"Content-Type: application/json"
]);

// Execute the request
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

// Output the result
if ($http_status == 200) {
echo "Message dispatched successfully: " . response;
}
?>

Webhooks in PHP

To receive delivery receipts (to know if the user actually read your PHP-dispatched message), you can create a simple webhook.php file that reads the incoming JSON payload via file_get_contents('php://input') and updates your local MySQL database accordingly.

With just a few lines of PHP, you can transform a legacy CRM into a real-time, conversational engine powered by the global WhatsApp network.

Ready to upgrade your infrastructure?

Start Building with 5MinutesAPI