Last active
August 28, 2024 06:03
-
-
Save daveh/6a31d0d28d9aef8c161c6ff1b6d29fae to your computer and use it in GitHub Desktop.
Send SMS Messages with PHP (code to accompany https://youtu.be/obolAwbx388)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>PHP SMS</title> | |
<meta charset="UTF-8" /> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" /> | |
</head> | |
<body> | |
<h1>PHP SMS</h1> | |
<form method="post" action="send.php"> | |
<label for="number">Number</label> | |
<input type="text" name="number" id="number" /> | |
<label for="message">Message</label> | |
<textarea name="message" id="message"></textarea> | |
<fieldset> | |
<legend>Provider</legend> | |
<label> | |
<input type="radio" name="provider" value="infobip" checked /> Infobip | |
</label> | |
<br /> | |
<label> | |
<input type="radio" name="provider" value="twilio" /> Twilio | |
</label> | |
</fieldset> | |
<button>Send</button> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Infobip\Configuration; | |
use Infobip\Api\SmsApi; | |
use Infobip\Model\SmsDestination; | |
use Infobip\Model\SmsTextualMessage; | |
use Infobip\Model\SmsAdvancedTextualRequest; | |
use Twilio\Rest\Client; | |
require __DIR__ . "/vendor/autoload.php"; | |
$number = $_POST["number"]; | |
$message = $_POST["message"]; | |
if ($_POST["provider"] === "infobip") { | |
$base_url = "https://your-base-url.api.infobip.com"; | |
$api_key = "your API key"; | |
$configuration = new Configuration(host: $base_url, apiKey: $api_key); | |
$api = new SmsApi(config: $configuration); | |
$destination = new SmsDestination(to: $number); | |
$message = new SmsTextualMessage( | |
destinations: [$destination], | |
text: $message, | |
from: "daveh" | |
); | |
$request = new SmsAdvancedTextualRequest(messages: [$message]); | |
$response = $api->sendSmsMessage($request); | |
} else { // Twilio | |
$account_id = "your account SID"; | |
$auth_token = "your auth token"; | |
$client = new Client($account_id, $auth_token); | |
$twilio_number = "+ your outgoing Twilio phone number"; | |
$client->messages->create( | |
$number, | |
[ | |
"from" => $twilio_number, | |
"body" => $message | |
] | |
); | |
} | |
echo "Message sent."; |
How do i make my name display when receiver receives the sms
When i send rather than getting Mutual i got InfoSMS
$message = new SmsTextualMessage(
destinations: [$destination],
text: $message,
from: "Mutual"
Its saying message sent but not getting any message😕🤦🏻
@edwardklem Check the provider's dashboard for the sending logs
its not working right now
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hii