Note: The Free API is only for personal use.
CallMeBot API can send WhatsApp Text Messages from your PHP scripts with a few lines of code. You can either use the cURL library or simple call to the get_file_contents function.

See below the step-by-step instructions to send Whatsapp Messages from PHP.

Setup:

You need to get the apikey form the bot before using the API:

1. Add the phone number +34 644 43 38 04 into your Phone Contacts. (Name it it as you wish)

  1. Send this message "I allow callmebot to send me messages" to the new Contact created (using WhatsApp of course)
  2. Wait until you receive the message "API Activated for your phone number. Your APIKEY is 123123" from the bot.
    Note: If you don't receive the ApiKey in 2 minutes, please try again after 24hs.
  3. The WhatsApp message from the bot will contain the apikey needed to send messages using the API.

You can send text messages using the API after receiving the confirmation.

Example:
58

5. Enjoy

5. Note, If you need any of the capabilities listed below, please check https://textmebot.com (low cost) or https://www.twilio.com/ (best official provider)
    - Send messages to others
    - Send messages to Groups
    - Send messages from your whatsapp number
    - Send Images
    - Send Buttons
    - Send documents
    - Receive the answers

How to send WhatsApp Messages from PHP using CURL Library

It is very simple to send WhatsApp messages from PHP using the cURL Library. I would recommend to create a function and then call to the function every time that you want to send a message.

First, create the function "send_whatsapp" in your php code as follow:

function send_whatsapp($message="Test"){
    $phone="+49123123123";  // Enter your phone number here
    $apikey="123456";       // Enter your personal apikey received in step 3 above

    $url='https://api.callmebot.com/whatsapp.php?source=php&phone='.$phone.'&text='.urlencode($message).'&apikey='.$apikey;

    if($ch = curl_init($url))
    {
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); $html = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); // echo "Output:".$html; // you can print the output for troubleshooting curl_close($ch); return (int) $status; } else { return false; } }

Just update the $phone and $apikey variable with the ones that you obtained during the step 3 above.

And then call to the function from any place in your code.

send_whatsapp("this is a test from PHP");    //Text message that your would like to send

You can call to the send_whatsapp function from different places in your code.

 

How to send WhatsApp Messages from PHP using file_get_contents

A simpler way to send a whatsapp message is using the file_get_contents function.

$phone='+49123123123';
$apikey='123456'; $message='This is a test from PHP'; $url='https://api.callmebot.com/whatsapp.php?source=php&phone='.$phone.'&text='.urlencode($message).'&apikey='.$apikey; $html=file_get_contents($url);

You can also create a function and call it from different places from your code, it really depends on your code.

Problems?

If you have problems, like not receiving the Call on Telegram, or not receiving the WhatsApp messages,  try to test the CallMeBot API using your Web Browser:

  • Telegram Phone Calls using Web Browser: here
  • Telegram Text Messages using Web Browsers: here
  • WhatsApp Text Messages using Web Browser: here

You might get some errors on the screen that will help you to identify the problem. (Ex: Calls disabled in the Telegram Security Settings, WhatsApp not activated, etc.)

If you still have problems using the API, don’t hesitate to contact me in Telegram @callmebot_com or by email at [email protected]. Remember to Follow me on Twitter to get news about coming features, changes, invitations, etc.