[英]Send SMS to phone - php form removing ( ) and - from the phone number submitted
我有一个在网上找到的脚本,该脚本试图获取10位数字的电话号码,然后添加移动服务提供商以将电子邮件发送到SMS。
有用。 但...
我的前端表单是自动输入“(”,“)”和“-” 括号和破折号 ,使其看起来更像电话号码。 php脚本无法正常工作,因为您必须发送没有任何内容的电子邮件,只有0、1、2、3、4、5、6、7、8、9可以正常工作。
您可以在此处看到前端表单。 通过单击“发送到电话”, http://busetopizza.com/demo/index.php
您注意到它将发送(516)-233-2333作为提交。
我需要帮助重写代码以去除字符,然后将其重新评估为某种形式,以便它将作为5162332333发送。
随附的是php代码。可以这样做吗?
<?php
if (!isset($_POST['submit'])){error("Must use form to get here!");}
$ph = $_POST['10digit'];
$carrier = $_POST['carrier'];
switch ($carrier){
case 'att':
$to = $ph . '@txt.att.net';
break;
case 'metropcs':
$to = $ph . '@mymetropcs.com';
break;
case 'nextel':
$to = $ph . '@messaging.nextel.com';
break;
case 'sprint':
$to = $ph . '@messaging.sprintpcs.com';
break;
case 'tmobile':
$to = $ph . '@tmomail.net';
break;
case 'verizon':
$to = $ph . '@vtext.com';
break;
case 'virgin':
$to = $ph . '@vmobl.com';
break;
default:
error("No carrier selected, message not sent!");
}
$message = "http://www.busetopizza.com/";
$subject = "Send To Phone App";
$from = "admin@messtudios.com";
mail($to, $subject, $message, $from);
echo "Your message has been sent!";
exit();
function error($msg){
echo "An error has occurred: ".$msg;
exit();
}
?>
编辑以下行以使用正则表达式查找并替换输入中的所有非数字字符。
$ph = preg_replace('/[^[:digit:]]/', '', $_POST['10digit']);
您可以使用正则表达式从输入中删除非数字数字。
$pattern = '/[^0-9]*/';
$ph = preg_replace($pattern,'', $_POST['10digit']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.