A
A
Alexander2015-12-16 17:33:23
PHP
Alexander, 2015-12-16 17:33:23

How to send SMS using PHP in Raspbian?

I can't figure out how to send SMS using PHP.
Device: Raspberry Pi,
Axis: Raspbian,
Software: Gammu.
Sending from the command line:

gammu sendsms TEXT +79876543210 -textutf8 "Proverka"

Help with PHP code.
It doesn't work like this:
$command = 'gammu sendsms TEXT +79509791173 -textutf8 "Proverka"';
$output = shell_exec($command);
echo "<pre>$output</pre>";
echo $output;
/* СМС не отправляет. Выводит на экран
Warning: No configuration file found!
Warning: No configuration read, using builtin defaults!
Error opening device, it doesn't exist.
Warning: No configuration file found! Warning: No configuration read, using builtin defaults! Error opening device, it doesn't exist.
*/
----------------------------------------------------------------------------------
$command = 'sudo gammu sendsms TEXT +79509791173 -textutf8 "Proverka"';
$output = shell_exec($command);
echo "<pre>$output</pre>";
echo $output;
/* СМС не отправляет. Ничего не выводит */
----------------------------------------------------------------------------------
$command = 'sudo /usr/bin/gammu sendsms TEXT +79509791173 -textutf8 "Proverka"';
$output = shell_exec($command);
echo "<pre>$output</pre>";
echo $output;
/* СМС не отправляет. Ничего не выводит */

The gammu-config file is located in the folder with this script.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Michael, 2015-12-16
@Remdev

Perhaps the permissions on the configuration file are set incorrectly and when running from php it is impossible to read it

O
OnYourLips, 2015-12-16
@OnYourLips

You have clearly been told what the error is:
And it works from the command line, because the environment variables (including HOME, in which the configs are located) are from your user, and not www-data.

A
Alexander, 2015-12-17
@daapp

Either specify for gammu even before the configuration file (if it understands this), or specify everything that it needs (port device name, port parameters, etc.) when calling gammu.

P
planc, 2016-01-18
@planc

On Linux, MacOS X, BSD and other Unix-like systems, the config file is searched in following order:
$XDG_CONFIG_HOME/gammu/config
~/.config/gammu/config
~/.gammurc
/etc/gammurc
drop the config at /etc/gammurc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question