PHP - Twilio SMS MySQL 多个号码 - 只发送到第一行
PHP - Twilio SMS MySQL Multiple Numbers - Only sends to first row
首先,我 运行 使用此代码获取 Twilio SMS 的 phone 号码、名字和姓氏。
$users_query = mysql_query("SELECT first_name, last_name, phone_no from users WHERE phone_no!=''");
$users = array();
while($row = mysql_fetch_array($users_query))
{
$users[]=$row;
}
然后我用它来发送短信,它应该发送到 phone_no 列中的所有号码。
foreach($users as $user)
{
$people = array(
//$phone_no => $full_name
$user['phone_no'] => $user['first_name'].' '. $user['last_name']
);
}
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
try{
$sms = $client->account->messages->create(
// the number we are sending to - Any phone number
$number,
array(
目前短信只发送第一行phone号码。我卡住了。
这是正常的...这样做
$people = [];
foreach($users as $user)
{
$people[] = array(
'full_name' => $user['first_name'].' '. $user['last_name'],
'phone_no' => $user['phone_no'],
);
}
foreach ($people as $one) {
$name = $one['full_name'];
$phone = $one['phone_no'];
$sms = $client->account->messages->create(
$phone,
array(
'from' => "+15017250604",
'body' => "Hey $name, Monkey Party at 6PM. Bring Bananas!"
)
);
echo "Sent message to $name";
}
您应该将 $people 声明为数组。然后在循环中你必须添加到 $people 这个 []
首先,我 运行 使用此代码获取 Twilio SMS 的 phone 号码、名字和姓氏。
$users_query = mysql_query("SELECT first_name, last_name, phone_no from users WHERE phone_no!=''");
$users = array();
while($row = mysql_fetch_array($users_query))
{
$users[]=$row;
}
然后我用它来发送短信,它应该发送到 phone_no 列中的所有号码。
foreach($users as $user)
{
$people = array(
//$phone_no => $full_name
$user['phone_no'] => $user['first_name'].' '. $user['last_name']
);
}
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
try{
$sms = $client->account->messages->create(
// the number we are sending to - Any phone number
$number,
array(
目前短信只发送第一行phone号码。我卡住了。
这是正常的...这样做
$people = [];
foreach($users as $user)
{
$people[] = array(
'full_name' => $user['first_name'].' '. $user['last_name'],
'phone_no' => $user['phone_no'],
);
}
foreach ($people as $one) {
$name = $one['full_name'];
$phone = $one['phone_no'];
$sms = $client->account->messages->create(
$phone,
array(
'from' => "+15017250604",
'body' => "Hey $name, Monkey Party at 6PM. Bring Bananas!"
)
);
echo "Sent message to $name";
}
您应该将 $people 声明为数组。然后在循环中你必须添加到 $people 这个 []