• 0

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/post.php

Line Number: 190


File: /home2/naijacod/public_html/application/views/post.php
Line: 190
Function: _error_handler

File: /home2/naijacod/public_html/application/controllers/Posts.php
Line: 420
Function: view

File: /home2/naijacod/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to send a PDF file to a WhatsApp user in PHP

This article shows you how to send a document (e.g. a PDF file, an MP4 file, a WAV file, etc.) to a registered WhatsApp user in PHP.

Before the recipient can receive your WhatsApp message, she MUST register with the WhatsMate WA Gateway. Instructions are available on the official siteUnregistered users will never receive messages from the Gateway.

To send a WhatsApp message containing a PDF document in PHP, do this:

  1. First, learn how to send a simple text message on the official site.
  2. With the above knowledge, you can now download our sample code.
  3. Locate the file php/send-pdf-individual.php.
      $INSTANCE_ID = 'YOUR_INSTANCE_ID_HERE'; // TODO: Replace it with your gateway instance ID here
      $CLIENT_ID = "YOUR_CLIENT_ID_HERE"; // TODO: Replace it with your Premium client ID here
      $CLIENT_SECRET = "YOUR_CLIENT_SECRET_HERE"; // TODO: Replace it with your Premium client secret here
      $pathToDocument = "/tmp/your_doc.pdf"; // TODO: Replace it with the path to your document
      $docData = file_get_contents($pathToDocument);
      $base64Doc = base64_encode($docData);
      $fn = "anyname.pdf"; // TODO: Replace it with a name you like
      $postData = array(
      'number' => '12025550108', // TODO: Specify the recipient's number (NOT the gateway number) here.
      'document' => $base64Doc,
      'filename' => $fn
      $headers = array(
      'Content-Type: application/json',
      $url = 'http://api.whatsmate.net/v3/whatsapp/single/document/message/' . $INSTANCE_ID;
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
      $response = curl_exec($ch);
      echo "Response: ".$response;


  4. Study the PHP source code and customize the TODO/FIXME lines.

    • Among other things, put down YOUR OWN number as the recipient. You can’t send messages to strangers because we are against SPAMMERS.
  5. Visit the PHP page you just created to send your image.

Happy coding :)