Sending Text Messages Via PHP

August 26th, 2009 by Eric Williams Leave a reply »

Sunday is family day for us. We try on most Sundays to get together for lunch after church. It is nice to get together and catchup on what is happening in everyone’s lives.

The problem is it is so hard to get everyone to agree on a restaurant! Honestly this is usually a 15 to 20 minute ordeal. Lots of I don’t care, whatever you want, anything but that kind of comments.

The solution, write down all the restaurants within a 5 mile radius that everyone can tolerate, then either go down the list or choose randomly.

Below is a fun little script that I wrote to choose a random restaurant and text the results too us.

Most of the cell phone carriers allow sending of text messages via email Verizon’s format is thenumber@vtext.com, other carriers you will have to check.

set_time_limit(0);

//Creating Restaurants List
$restaurants = array();
$restaurants = array("Applebees", "Red Lobster", "Red Robin", "Chilis", "Sweet Tomatos", "Culvers", "Olive Garden", "Macayos", "Rio Marage", "Golden Corral", "Brookside", "Chipolte", "My Greek Corner", "Fridays", "Paridise Bakery", "Chuy's", "Streets of New York", "Taco Bell", "Charleys", "Wendy's", "Long John Silvers", "Out Back", "Buffalo Wild Wings", "Burger King", "A&W KFC", "NYPD Pizza");

//Selecting Random Restaurant
$rand_restaurant = array_rand($restaurants,1);

//Creating Email List
$emailaddress = array();
$emailaddress = array("1111111111@vtext.com,2222222222@vtext.com");

//Setting Email Properties
$emailsubject = "Today we are eating at....";
$emailbody = $restaurants[$rand_restaurant];
$fromaddress = "you@youremail.com";

//Getting email Count
$i = count($emailaddress);

$z = 0;

//Loop only if we have some email addresses
if ($i != 0)

{

while ($i != $z)

{
// Send the Mail
mail($emailaddress[$z], $emailsubject, $emailbody, "From: " .$fromaddress. "\nX-Mailer: PHP 4.x");

echo $z + 1 . " out of " . $i . " emails sent. (" . $emailaddress[$z] . ")
";

++$z;

}

}

else

{

echo "Warning: No emails in array.";
}

Also I wanted the text to be sent out every Sunday at 10:05AM so I added the following line to /etc/crontab

5 10 * * sun php /path/to/file.php

Advertisement

Leave a Reply