Contact Form 7 inquiries go Email and WhatsApp automatically

Contact Form 7 WhatsApp integration, send form to WhatsApp, WordPress inquiry WhatsApp, Contact Form 7 email WhatsApp, WhatsApp Cloud API WordPress

Same time, the details are sent automatically to your WhatsApp using the WhatsApp Cloud API.

Step 1: Create Contact Form 7 Form

Add a new CF7 form with this shortcode:

[contact-form-7 id="123" title="Inquiry Form"]
<p>
  Name (required)<br>
  [text* your-name] 
</p>
<p>
  Email (required)<br>
  [email* your-email] 
</p>
<p>
  Phone<br>
  [tel your-phone] 
</p>
<p>
  Message<br>
  [textarea your-message] 
</p>
<p>
  [submit "Send Inquiry"]
</p>

Replace 123 with your actual form ID.

Step 2: Email Setup

In the Mail tab of CF7, configure:

To: yourmail@example.com
Subject: New Inquiry from Website
Message Body:

Name: [your-name]
Email: [your-email]
Phone: [your-phone]
Message: [your-message]

This ensures you get inquiries in your email.

Step 3: WhatsApp Auto-Send (functions.php)

Now add this code to your theme’s functions.php or a site-specific plugin:

// Send Contact Form 7 inquiry to WhatsApp Cloud API
add_action('wpcf7_mail_sent', 'cf7_send_to_whatsapp');

function cf7_send_to_whatsapp($contact_form) {
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
        $data = $submission->get_posted_data();

        // Collect form fields
        $name    = sanitize_text_field($data['your-name']);
        $email   = sanitize_email($data['your-email']);
        $phone   = sanitize_text_field($data['your-phone']);
        $message = sanitize_textarea_field($data['your-message']);

        // Format WhatsApp message
        $msg = "πŸ“© *New Inquiry Received* \n\n".
               "πŸ‘€ Name: $name\n".
               "πŸ“§ Email: $email\n".
               "πŸ“ž Phone: $phone\n".
               "πŸ’¬ Message: $message";

        // WhatsApp Cloud API credentials
        $url = "https://graph.facebook.com/v19.0/YOUR_PHONE_NUMBER_ID/messages";
        $token = "YOUR_ACCESS_TOKEN";

        // Replace with your destination WhatsApp number
        $recipient = "91XXXXXXXXXX";

        $body = json_encode([
            "messaging_product" => "whatsapp",
            "to" => $recipient,
            "type" => "text",
            "text" => ["body" => $msg]
        ]);

        $args = [
            'body'    => $body,
            'headers' => [
                'Authorization' => 'Bearer '.$token,
                'Content-Type'  => 'application/json'
            ]
        ];

        wp_remote_post($url, $args);
    }
}

Step 4: Replace with Your Details

  • YOUR_PHONE_NUMBER_ID β†’ from Meta WhatsApp Cloud API setup.

  • YOUR_ACCESS_TOKEN β†’ permanent access token from Meta Developer Portal.

  • 91XXXXXXXXXX β†’ your WhatsApp number (with country code, no +).

 

Now, when a user submits the form:

  • You’ll get an email with inquiry details.

  • The same details will be pushed to your WhatsApp automatically.

Previous Article

Enquiry sent automatically to WhatsApp

Next Article

Issue: cURL requests (used for DB/API communication) stopped working

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨