PHP Sites Integration | CallMeBack Documentation

PHP Sites Integration

Integrate CallMeBack with your custom PHP website to capture leads and provide instant callback requests. This guide covers multiple integration methods for PHP-based websites.

Quick Start

Get CallMeBack live on your PHP site in under 5 minutes using the header include method.

Prerequisites

  • A CallMeBack account (get one at callmeback.com)
  • Access to your PHP website files
  • Your CallMeBack integration code (found in your dashboard)
  • Basic knowledge of PHP and HTML

Integration Methods

Method 1: Header Include (Recommended)

This method adds the CallMeBack widget to all pages by including it in your site's header file.

Steps:

  1. Locate your main header file (usually header.php or includes/header.php)
  2. Find the </head> tag
  3. Add your CallMeBack integration code just before the closing </head> tag
  4. Save the file and test your website

Note

Always backup your files before making changes. This method affects all pages that use this header.

Method 2: PHP Function

Create a PHP function to include CallMeBack with more control over when and where it appears.

Steps:

  1. Create a new file called callmeback.php in your includes directory
  2. Add the following code to the file:
<?php
function include_callmeback() {
    // Your CallMeBack integration code here
    echo '<script>/* Your CallMeBack code */</script>';
}

// Call the function where needed
include_callmeback();
?>

Pro Tip

This method gives you the flexibility to include CallMeBack only on specific pages or under certain conditions.

Method 3: Conditional Inclusion

Include CallMeBack only on specific pages or under certain conditions.

Steps:

  1. Add this code to your header file or main template
<?php
// Include CallMeBack only on contact page
if (strpos($_SERVER['REQUEST_URI'], 'contact') !== false) {
    echo '<script>/* Your CallMeBack code */</script>';
}

// Or include on specific pages
$current_page = basename($_SERVER['PHP_SELF']);
$pages_with_widget = array('contact.php', 'about.php', 'services.php');

if (in_array($current_page, $pages_with_widget)) {
    echo '<script>/* Your CallMeBack code */</script>';
}
?>

Strategic Placement

This method ensures the widget only appears where it's most needed, keeping your site clean and focused.

Method 4: PHP Form Integration

Integrate CallMeBack directly with your PHP forms for seamless lead capture.

Steps:

  1. Create a PHP script to handle form submissions
  2. Add CallMeBack API integration to your form processing
  3. Send form data to CallMeBack when forms are submitted
<?php
if ($_POST) {
    // Process your form data
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $name = $_POST['name'];
    
    // Send to CallMeBack API
    $callmeback_data = array(
        'email' => $email,
        'phone' => $phone,
        'name' => $name,
        'source' => 'php_form'
    );
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.callmeback.com/webhook');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($callmeback_data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    // Handle response
    if ($response) {
        echo "Thank you! We'll call you back soon.";
    }
}
?>

Advanced Integration

This method integrates CallMeBack directly with your existing PHP forms for seamless lead capture.

Supported PHP Frameworks

CallMeBack works with various PHP frameworks and CMS:

  • Laravel
  • CodeIgniter
  • Symfony
  • CakePHP
  • Yii
  • Custom PHP applications
  • PHP-based CMS systems

Testing Your Integration

How to Test:

  1. Visit your PHP website
  2. Look for the CallMeBack widget (floating button or embedded form)
  3. Click the widget to open the callback form
  4. Fill out the form with test information
  5. Submit the form and check your CallMeBack dashboard
  6. Verify that you receive the callback request notification
  7. Test on different pages if using conditional inclusion

Troubleshooting

Widget Not Appearing

  • Check that your integration code is correctly placed in the HTML
  • Verify the code is in the <head> section
  • Clear your browser cache and refresh the page
  • Check browser console for JavaScript errors
  • Verify your CallMeBack account is active
  • Check PHP error logs for any issues

Form Submissions Not Working

  • Ensure your CallMeBack account has available credits
  • Check that the form fields match CallMeBack requirements
  • Verify your API integration code is correct
  • Test with a different browser or device
  • Check PHP error logs for curl or API issues
  • Verify your server can make outbound HTTP requests

PHP Errors

  • Check PHP syntax in your integration code
  • Verify all PHP tags are properly closed
  • Check for missing semicolons or brackets
  • Ensure your PHP version supports the features you're using
  • Check server error logs for detailed error messages

Advanced Configuration

Custom Styling

You can customize the widget appearance by adding CSS to your PHP site:

<style>
/* Add this to your CSS file or in a <style> tag */
.callmeback-widget {
  /* Your custom styles here */
}

.callmeback-button {
  background-color: #your-brand-color !important;
  border-radius: 8px !important;
  font-family: inherit !important;
}

/* PHP-specific styling */
.callmeback-widget {
  z-index: 9999;
  position: fixed;
}
</style>

PHP Integration Tips

You can also use PHP to dynamically generate CSS variables or include different styles based on your site's configuration.

Security Considerations

Important Security Notes:

  • Always validate and sanitize form data before sending to CallMeBack
  • Use HTTPS for all API communications
  • Implement proper CSRF protection for forms
  • Store API keys securely (use environment variables)
  • Implement rate limiting for form submissions
  • Log API interactions for debugging and security

Need Help?

If you're having trouble with your PHP integration:

Ready to get started?

Create your CallMeBack account and start capturing leads today.