Gammu adalah aplikasi open-source yang memungkinkan kamu mengirim dan menerima SMS melalui komputer menggunakan handphone atau modem yang terhubung. SMS Gateway dengan Gammu banyak digunakan untuk notifikasi, verifikasi OTP, dan komunikasi otomatis.
Gammu (GNU All Mobile Management Utilities) adalah tools untuk mengelola handphone dan modem. Gammu mendukung berbagai merek handphone dan modem GSM/CDMA. Dengan Gammu, kamu bisa mengirim SMS, menerima SMS, mengelola kontak, dan banyak lagi.
# Windows - download dari https://wammu.eu/download/ # Jalankan installer dan ikuti wizard # Linux (Ubuntu/Debian) sudo apt update sudo apt install gammu gammu-smsd # CentOS/RHEL sudo yum install gammu gammu-smsd Buat file konfigurasi gammurc:
# ~/.gammurc atau /etc/gammurc [gammu] device = /dev/ttyUSB0 connection = at # Untuk Windows: device = COM3 atau COM4 Identifikasi port yang digunakan:
# Cek port yang tersedia gammu --identify # Kirim SMS teks biasa gammu sendsms TEXT 08123456789 -text "Halo dari Gammu!" # Kirim SMS dari file gammu sendsms TEXT 08123456789 -textfile message.txt # Kirim SMS flash (langsung muncul di layar) gammu sendsms TEXT 08123456789 -flash SMSD adalah service background yang otomatis memproses SMS masuk dan keluar. Buat konfigurasi SMSD:
# /etc/gammu-smsdrc [gammu] device = /dev/ttyUSB0 connection = at [smsd] service = files logfile = /var/log/gammu-smsd.log inboxpath = /var/spool/gammu/inbox/ outboxpath = /var/spool/gammu/outbox/ sentsmspath = /var/spool/gammu/sent/ errorsmspath = /var/spool/gammu/error/ # Jalankan SMSD sudo gammu-smsd -c /etc/gammu-smsdrc # Atau sebagai service sudo systemctl start gammu-smsd Buat script PHP untuk mengirim SMS:
<?php function sendSMS($number, $message) { $cmd = "gammu sendsms TEXT {$number} -text " . escapeshellarg($message); $output = shell_exec($cmd); return $output; } // Kirim SMS $result = sendSMS("08123456789", "Verifikasi kode kamu: 123456"); echo $result; ?> Buat tabel MySQL untuk menyimpan data SMS:
CREATE TABLE sms_log ( id INT AUTO_INCREMENT PRIMARY KEY, phone_number VARCHAR(20) NOT NULL, message TEXT NOT NULL, direction ENUM('in', 'out') NOT NULL, status ENUM('pending', 'sent', 'failed') DEFAULT 'pending', created_at DATETIME DEFAULT CURRENT_TIMESTAMP ); Buat script untuk memproses SMS masuk dan mengirim balasan otomatis:
<?php // Baca SMS dari inbox $inbox_path = '/var/spool/gammu/inbox/'; $files = glob($inbox_path . '*.txt'); foreach ($files as $file) { $content = file_get_contents($file); // Parse SMS content // Kirim balasan // Hapus file setelah diproses unlink($file); } ?> Gammu adalah solusi SMS Gateway yang murah dan reliable untuk kebutuhan bisnis. Dengan Gammu, kamu bisa mengirim SMS otomatis, menerima SMS, dan mengintegrasikannya dengan aplikasi web. Cocok untuk sistem notifikasi, verifikasi OTP, dan marketing SMS.
Yang perlu disiapkan:
Buat file konfigurasi gammurc:
[gammu]
device = /dev/ttyUSB0
connection = at
name = Phone on USB serial port
<?php
function kirimSMS($nomor, $pesan) {
$cmd = "gammu --sendsms TEXT " . escapeshellarg($nomor) .
" -textutf8 " . escapeshellarg($pesan);
exec($cmd, $output, $return);
return $return === 0;
}
// Penggunaan
$result = kirimSMS("08123456789", "Test SMS dari PHP");
echo $result ? "SMS terkirim" : "Gagal mengirim SMS";
?>
gammu --identify