Recently, I had a need to send a reminder text message at a given time on a daily basis. Creating a PHP script to send a message to a phone is extraordinarily simple, its a mail form that emails the phone in question using the following email address format:
<phone number>@carrierdomain.com
I chose to use PEAR Mail and had my script authenticate with Gmail to personalize the message. If you use the local SMTP service and do not authenticate with an external mail server, your messages will originate from the server’s hostname.
A list of domains for all cell phone carriers can be found here:
Cell Phone Carrier Domains
Once the script was tested and working, it was configured to run at 10:45am using crontab.
Crontab Quick-Reference
Note: This script does not contain error checking.
/*
* Date created: 08/11/11
* PEAR Mail script to send a message using SMTP Authentication to send through Gmail.
*/
include("Mail.php");
$recipients = "5555555555@tmomail.net"; //Must use 10-digit number [include area code]
$headers["From"] = "user@gmail.com";
$headers["To"] = "5555555555@tmomail.net"; //T-Mobile
$mailmsg = "This is a text message";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "ssl://smtp.gmail.com";
$smtpinfo["port"] = "465";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "user@gmail.com";
$smtpinfo["password"] = "password";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);