我有一个在网上找到的脚本,它试图获取 10 位数的电话号码,然后添加移动提供商以向短信发送电子邮件。
它有效。但。。。
我的前端表单会自动输入"(",")"和"-"括号和破折号,使其看起来更像电话号码。 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']);