Created
May 23, 2014 23:20
-
-
Save javierwilson/a14a5d457dc7f2c18d23 to your computer and use it in GitHub Desktop.
Send Bulk SMS using Twilio
This file contains hidden or 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 | |
require('Services/Twilio.php'); | |
$sid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; | |
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
$from = "5555555555"; | |
require('config.php'); | |
#+555555555555,Alice Smith,CT | |
#+555555555555,Bob Rodriguez,LTO 01A | |
$ALL = file('all.txt'); | |
foreach ($ALL as $line) { | |
$line = chop($line); | |
list($number,$name,$group) = preg_split('/,/', $line); | |
list($group, $group2) = preg_split('/ /', $group); | |
$groups[$group][] = $number; | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Twilio SMS bulk</title> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="starter-template"> | |
<h1>Twilio SMS bulk</h1> | |
<form method="POST"> | |
Group: | |
<select name="group"> | |
<option value="none">--</option> | |
<?php | |
foreach ($groups as $key => $val) { | |
echo "<option value=\"$key\">$key</option>"; | |
} | |
?> | |
</select> | |
<br/> | |
Individual:<br/> | |
<select size="6" multiple="multiple" name="nos[]"> | |
<?php | |
foreach ($ALL as $line) { | |
$line = chop($line); | |
list($number,$name,$group) = preg_split('/,/', $line); | |
echo "<option value=\"$number\">$group - $name</option>"; | |
} | |
?> | |
</select> | |
<br/> | |
Message:<br/> | |
<textarea name="text" cols="40" rows="10"> | |
<?=$_REQUEST['text']?> | |
</textarea> | |
<br/> | |
<input type="submit" value="Send SMS"/> | |
</form> | |
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> | |
</div> | |
</div><!-- /.container --> | |
</body> | |
</html> | |
<?php | |
$client = new Services_Twilio($sid, $token); | |
$text = $_REQUEST['text']; | |
$group = $_REQUEST['group']; | |
$nos = $_REQUEST['nos']; | |
if($group != 'none') { | |
foreach ($groups as $key => $val) { | |
if ($key == $group) | |
$groupnos[] = $val; | |
} | |
$nos = array_merge($nos, $groupnos[0]); | |
} | |
foreach ($nos as $no) { | |
print "$no = "; | |
$message = $client->account->messages->sendMessage($from,$no,$text); | |
print $message->sid; | |
print "<br/>\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice code...but where can I find the config.php file?