I am having a little trouble with the code and was wondering if I could get your help. It seems that I can't get the handler code to communicate with the form.
Printable View
I am having a little trouble with the code and was wondering if I could get your help. It seems that I can't get the handler code to communicate with the form.
marlowjust, send me your code and we'll have a look!
I just used the same code you posted and made two files out of it. One a php file and the other html file. Then uploaded the two of them to my server. I'm more of a beginner working with php and such so I know I've done something wrong. Should I modify anything other than the email address gateway for phone providers? I can get everything to display properly but when I hit submit text nothing happens.
marlowjust,
Are you sure your form is submitting to the php script? On the first line of code I posted for the form, you'll see the action attribute being set:
This is a relative link, so you'll need to make sure that relative to the file with the HTML form in it, the php script is names send_sms.php and in a folder called scripts. Alternatively, you could change the action attribute to point to the location of the php form handler file.Code:action="scripts/send_sms.php"
If this doesn't help, just let me know. A URL would help too, if at all possible.
Cheers,
Zach
Perfect, that worked and I can now text! I was also wondering...is there a way I make it so when the person texting on my page can enter their email address and it will show up to the person receiving the text? Right now a text says it is from name@server03-01.hostingcomplex.com
I've always wanted to enable replies to a person's email address. I've seen some other texting sites do it but now sure what all that would involve. Thank you for your help.
Sure, just set your own mail headers. Here's a basic example:
For more information, check out the PHP manual for mail() at http://us2.php.net/manual/en/function.mail.php. Scroll down to the description for additional_headers to see all your options. I don't know if you've used the PHP manual in the past, but it is by far the best documentation I've found for the language. And it's free!Code:$Email = $_POST['Email'];
// Collect other variables from POST here
mail($PhoneNumber, $Subject, $Message, 'From: ' . $Email);
Let me know if you need anything else,
Zach
Would be easier to do something like this.
Any errors get caught like if the mail attempt fails.PHP Code:<?php
$from = $_POST[ 'from' ];
$to = $_POST[ 'to' ];
$carrier = $_POST[ 'carrier' ];
$message = stripslashes( $_POST[ 'message' ] );
// are we empty? if not, continue
if ( !empty( $from ) && !empty( $to ) && !empty( $message ) ) {
// some carriers
$carriers_info = array(
"verizon" => "vtext.com",
"tmobile" => "tomomail.net",
"sprint" => "messaging.sprintpcs.com",
"att" => "txt.att.net",
"virgin" => "vmobl.com"
);
// test to see if the carrier exists in the array
if( in_array( $carrier , $carriers_info ) ){
// format the connection string
$formatted_number = $to . "@" . $carriers_info[ $carrier ];
// send the message
if( mail("$formatted_number", "SMS", "$message") ) header ( "Location: sms_success.php" );
}// end of if - in_array
}// end if - empty
header ( "Location: sms_error.php" );
?>
Certain hosts do not allow straight use of the mail send function, so take note, if you are unable to send then I suggest you consult your web host FAQ on this as each host will have their own method or process that you need to configure before you can send emails.
When trying to modify the handler so that it will display the user's email address to the person they are texting (for replies) I always run into an error. Here is what I'm trying to add..
Regular Handler
A regular send message script that will text to a number and display an email address from the sender.PHP Code:<?php
$from = $_POST[ 'from' ];
$to = $_POST[ 'to' ];
$carrier = $_POST[ 'carrier' ];
$message = stripslashes( $_POST[ 'message' ] );
// are we empty? if not, continue
if ( !empty( $from ) && !empty( $to ) && !empty( $message ) ) {
// some carriers
$carriers_info = array(
"verizon" => "vtext.com",
"tmobile" => "tomomail.net",
"sprint" => "messaging.sprintpcs.com",
"att" => "txt.att.net",
"virgin" => "vmobl.com"
);
// test to see if the carrier exists in the array
if( in_array( $carrier , $carriers_info ) ){
// format the connection string
$formatted_number = $to . "@" . $carriers_info[ $carrier ];
// send the message
if( mail("$formatted_number", "SMS", "$message") ) header ( "Location: sms_success.php" );
}// end of if - in_array
}// end if - empty
header ( "Location: sms_error.php" );
?>
The main thing I'm looking to do is add the request email function of the second script to the first script so it will request an email address and then display it in the "from" section of the text message. I've tried many times to mess with it and always get an error.PHP Code:<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "number@messaging.sprintpcs.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.example.com" );
?>
I wasn't paying much attention to detail, I just thought that as a routine it was easier to read and follow, anyway, theirs no difference, as long as the carrier is set then the resulting string will be made up of the additional parameters you include.
If any of the values you try to aquire or set in variable names can result in an error if they are not set. ensure that your passing all the required info.
The mail function is a bit short, what about adding & changing this instead.
PHP Code:if ( !empty( $from ) && !empty( $to ) && !empty( $message ) && !empty( $carrier ) ) {
You will also need to look up in your host FAQ on sending php mails, some do not allow, some do but with limits, some do not care and you can send as many as you like, check what your host required, one host I used did not allow the send mail function unless it had some other coding prior to and after the mail function as well as that the email address was forced via these external functions.PHP Code:$headers = "From: {$from}\r\nReply-To: {$from}\r\nX-Mailer: PHP/" . phpversion();
if( mail( $formatted_number, "SMS", $message, $headers) ) header ( "Location: sms_success.php" );
Hi, thanks for the information it seems to work great. I wanted to know what script to use if a person want to send the same message to more than one person. Say send same message 2 5 people who have the same carrier.
or is there some check box fields that can be embed as code. Thanks.
Don't know, sorry.
I would imagine something like, $recp would be text input boxes from a form but here I just use an array for demo.
... or something like thatPHP Code:$recp = array("user1@domin.com","user33@domin.com","user21@domin.com","user313@domin.com");
$snt=array();
foreach($recp as $key=>$sndmsg){
$snt[$key]=mail( $sndmsg, "SMS", $message, $headers);
}
$report = array("Your message was sent to:-<br>");
foreach($snt as $key=>$res) if($res) array_push($report,$recp[$key]."<br>");
if(in_array($snt,false)){
array_push($report,"The following were not sent:-<br>");
foreach($snt as $key=>$res) if(!$res) array_push($report,$recp[$key]."<br>");
}
$output = implode("\r\n",$report);
echo $output;
Hi, I need to send SMS(text messages) to Users having US mobile numbers from my PHP application. I do not know the service provider of those numbers? Will U please help me?
Sorry to revive an old thread but I have a question.
I cannot get this script to accept my from address, rather it replaces my from address with se@p5skj233.shr.phx8.secureserver.net
I am on a godaddy hosting plan, not sure how to fix this.
Thanks,
Stephen
Plz let me know if someone has gateway(s) for Pakistan
for sms sending you can use sms gateway, you can find some examples, one of them
PHP Code:<?
/*
Simple and easy for modification, PHP script for SMS sending through HTTP with you own Sender ID and delivery reports.
You just have to type your account information on www.2-waysms.com and upload file on server.
*/
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SMSER</title>
<style type="text/css">
body{
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
p, h1, form, button{border:0; margin:0; padding:0;}
.spacer{clear:both; height:1px;}
/* ----------- My Form ----------- */
.myform{
margin:0 auto;
width:300px;
padding:14px;
}
/* ----------- stylized ----------- */
#stylized{
border:solid 2px #b7ddf2;
background:#ebf4fb;
}
#stylized h1 {
font-size:14px;
font-weight:bold;
margin-bottom:8px;
}
#stylized p{
font-size:11px;
color:#666666;
margin-bottom:20px;
border-bottom:solid 1px #b7ddf2;
padding-bottom:10px;
}
</style>
</head>
<body>
<?
switch ($option) {
case sendsms:
if ($text == "") { echo "Error!<br>Text not entered<br><a href=\"javascript:history.back(-1)\">Go Back</a>"; die; } else { }
if ($to == "") { echo "Error!<br>Number not entered<br><a href=\"javascript:history.back(-1)\">Go Back</a>"; die; } else { }
$url = "http://www.2-waysms.com/sms.php";
$postfields = array ("text" => "$text", // do not need to change
"to" => "$to", // do not need to change
"id" => "*****", // you ID in www.2-waysms.com accout
"sec" => "****************************"); // your secret code in www.2-waysms.com account
if (!$curld = curl_init()) {
echo "Could not initialize cURL session.";
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curld, CURLOPT_URL, $url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close ($curld);
$out = explode('|',$output);
echo "Message Status: $out[1]";
//Header("Location: $PHP_SELF");
break;
default:
echo "<div id=\"stylized\" class=\"myform\">"
."<h1>Send Sms</h1>"
."<form method=post action=\"$PHP_SELF?option=sendsms\">"
."<table border=\"0\">"
."<tr>"
."<td>Number</td>"
."<td><input type=\"text\" name=\"to\"></td>"
."</tr>"
."<tr>"
."<td>Message</td>"
."<td><textarea rows=\"4\" cols=\"25\" name=\"text\"></textarea></td>"
."</tr>"
."<tr>"
."<td> </td>"
."<td><input type=submit name=submit value=Send>"
."<div class=\"spacer\"></div></td>"
."</tr>"
."</table>"
."</form>"
."</div>";
}
?>
</body>
</html>