从这个例子中很难看出你在做什么......请记住,其他联系号码不一定是唯一的,但手机号码*应该*是。如果您正在制作各种日志记录系统:
<?php
$cell_numbers = array(
'000-555-1212'=>'Charlie Sheen',
'800-333-4475'=>'Mary Poppins'
);
$sms = array();
//Number from the person texting
$inbound = $_POST['number'];
//Message from the person texting
$message = $_POST['message'];
if(!empty($cell_numbers[$inbound])){
$sms[][$number]=$message;
}
foreach($sms as $key=>$tempArr){
foreach($sms[$key] as $tNum=>$tMes){
echo "Message from ".$cell_numbers[$tNum]." - $tMes\n";
}
}
?>
如果你正在制作一个战争文本电子邮件应用程序,那么你可以这样做:
<?php
$contacts = array(
0=>array(
'number'=>'000-555-1212',
'name'=>'Charlie Sheen',
'carrier'=>'Sprint'),
1=>array(
'number'=>'800-333-4475',
'name'=>'Mary Poppins',
'carrier'=>'ATT'),
);
$carriers = array(
'ATT'=>'txt.att.net',
'Sprint'=>'messaging.sprintpcs.com',
'T-Mobile'=>'tomomail.net',
'Virgin'=>'vmobl.com',
'Verizon'=>'vtext.com',
);
$message = 'Do I know you?';
$sms = array();
foreach ($contacts as $key=>$tempArr){
$to = $contacts[$key]['number'].'@'.$carriers[$contacts[$key]['carrier']];
if(mail("$to","SMS","$message",$headers = 'From: Tom Hanks <911@vtext.com>' . "\r\n")){
$SMS[$to] = 'yes';
} else {
$SMS[$to] = 'failed';
}
}
?>