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 76 66 43 into your Phone Contacts. (Name it it as you wish)
  2. Send this message "I allow callmebot to send me messages" to the new Contact created (using WhatsApp of course)
  3. Wait until you receive the message "API Activated for your phone number. Your APIKEY is 123123" from the bot. As this is still in beta testing, the activation can take up to 2 minutes.
  4. 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:

  5. Enjoy

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.

Dedicated Telegram Bot for you and your Business

You can have your own dedicated bot to make the phone calls. 

These are the benefits of having your own bot:

  • Your own Telegram Username, Bio and Picture (Logo).
  • No delays. You will have your own queue.
  • Calls can be longer than 30 seconds
  • You can call to anybody without having the recipient to go through the authentication process. (Spam is not allowed)
  • Unlimited number of calls to unlimited recipients.

The cost of a dedicated instance is $15 per month. No setup fee. Minimum subscription period is 6 months.

If you are interested, please contact me at [email protected]

Thank you!

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.