tags:

views:

43

answers:

2

I have this code that sends a text message to your mobile phone...

$text = fopen("../data/textmembers/registry.txt","r") or die("couldent open file");

while (!feof($text)) {
$name = fgets($text);
$number = fgets($text);
$carrier = fgets($text);
$date = fgets($text);
$line = fgets($text);


$content = $_POST['message']; 

$message .= $content; 
$message .= "\n";
$number = trim($number);




mail($number . "@vtext.com", "SGA Event Alert", $message, "SGA"); 
Header("Location: mailconf.php");

everything works fine.. Here is my question, if you look at where I have "@vtext.com" as you may or may not know, each carrier has its own extension, verizon is @vtext.com, at&t is @txt.att.net. I need to take the feed from "$carrier" decide what carrier it is, and then assign the extension to it... I thought an ifelse would work, but I am not good with if statements... the user's choices are

Verizon = [email protected] AT&T = [email protected] T-mobile = @tmomail.net Nextel = @messaging.nextel.com

thanks guys!!

+1  A: 
$carriers = array(
  "verizon"  => "vtext.com",
  "at&t"     => "txt.att.net",
  "t-mobile" => "tmomail.net",
  "nextel"   => "messaging.nextel.com"
);

Then, you get that value by looking up the key:

print $carriers[strtolower($carrier)];

If $carrier is "Nextel," "messaging.nextel.com" will be returned.

Jonathan Sampson
thanks! but I get an error of "cannot find index"
Ryan
A: 

Probably better than using an if statement would be using a switch statement.

Have a look at the section of the PHP manual that deals with the switch statement.

eleven81