0

I want to send a message over WhatsApp from a php file. I've already discovered the library which let do it and it works in this way:

<?php
include_once './src/whatsprot.class.php';

function send($target,$message){
$username = "phone";
$password = "password";
$w = new WhatsProt($username,"Nickname", true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);

$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
}

send("phone","Text of the message");

?>

If I try to execute this or launch it via a php web server it works. If I try to call the method send($target,$message); from another php file, like this, it doesn't work:

 <?php 

include "whatsapp.php";

send($target, $message);

?>

What's the problem? How can I fix it?

1 Answer 1

1

If I try to call the method send($target,$message); from another php file, it doesn't work What's the problem?

Most probably another php file is located in a different directory and this command doesn't work:

include_once './src/whatsprot.class.php';

Try to use an absolute path to file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.