Hello,

I would like to enhance a website in that a user may send an SMS from it for free. Is this possible via a PHP script?

regards,
Pabzzmike

Dani AI

Generated

Short answer: yes — PHP can send SMS, but truly "free" delivery to arbitrary mobile numbers is rare. asked whether it’s possible for free; was correct that you need a gateway. There are three practical paths: a cloud SMS API (recommended for most web projects), an on‑premise GSM modem plus gateway software (one‑time hardware cost, limited throughput), or carrier email‑to‑SMS (sometimes free for proof‑of‑concept but unreliable and requires knowing the recipient carrier). ’s on‑premise idea and ’s advice to use a reputable provider are both valid choices depending on budget and scale.

Typical implementation steps: choose the approach, get API credentials or set up your modem, format numbers in E.164 (for example +15551234567), send over HTTPS from PHP, store the provider message ID and delivery receipts, and implement inbound webhooks for two‑way flows. For a local directory with SMS notifications (as described), use webhooks to map replies to listings, keep an audit trail, enforce opt‑in/opt‑out, and throttle notifications so owners aren’t spammed.

Minimal PHP example (generic REST API):

<?php
$apiKey = getenv('SMS_API_KEY');
$to = '+15551234567';
$message = 'New visit to your listing';

$payload = json_encode(['to'=>$to, 'message'=>$message]);

$ch = curl_init('https://api.example.com/v1/messages');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authorization: Bearer '.$apiKey,
  'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

Key gotchas and tips: keep API keys in environment variables, use HTTPS, watch encoding (GSM‑7 = 160 chars, UCS‑2 = 70 chars; multipart messages are billed per segment), verify webhook signatures, handle transient errors and retries, and read provider error codes for deliverability issues. For production, expect per‑message costs or a carrier plan; free tricks work only for limited testing.

Recommended Answers

All 4 Replies

You need an SMS gateway. If you search this website you'll find some.

I am Creating a local business directory with SMS interactive features to users to know when people visit their Company info. Search offline of the local directory via SMS. Any ideas that will help creating such a websites

I highly recommend using an industry leader. This is so that you're not just using an SMTP "SMS" messenger.
Try Clickatell. They look like they have a high reputation online.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.