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.
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.
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:
Code:
action="scripts/send_sms.php"
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.
If this doesn't help, just let me know. A URL would help too, if at all possible.
Cheers,
Zach
Last edited by TheYemboProject; 01-31-2009 at 01:27 PM.
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:
Code:
$Email = $_POST['Email'];
// Collect other variables from POST here
mail($PhoneNumber, $Subject, $Message, 'From: ' . $Email);
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!
else if ($carrier == "verizon") {
$formatted_number = $to."@vtext.com";
mail("$formatted_number", "SMS", "$message");
// Currently, the subject is set to "SMS". Feel free to change this.
// 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" );
?>
Any errors get caught like if the mail attempt fails.
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..
// 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" );
?>
A regular send message script that will text to a number and display an email address from the sender.
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.
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.
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.
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.
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?
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.
*/
?>
Bookmarks