...

View Full Version : Sending a text message via php



ghost2012
06-26-2010, 02:17 AM
I've been using a friends code to send an sms message via php. The only issue is that on receiving the message it gives out the hosting servers name. Now this I know can lead to a security issue. So am I'm turning to you guys to see what is it that I've missed.

This code uses the mail function of PHP
The default sub is set to TestingText

Here is the general form:

<form id="sms" name="sms" method="post" action="send.php">
<table width="400">
<tr>
<td align="right" valign="top">From:</td>
<td align="left"><input name="from" type="text" id="from" size="30" /></td>
</tr>
<tr>
<td align="right" valign="top">To:</td>
<td align="left"><input name="to" type="text" id="to" size="30" /></td>
</tr>
<tr>
<td align="right" valign="top">Carrier:</td>
<td align="left"><select name="carrier" id="carrier">
<option value="verizon">Verizon</option>
<option value="tmobile">T-Mobile</option>
<option value="sprint">Sprint</option>
<option value="att">AT&amp;T</option>
<option value="virgin">Virgin Mobile</option>
</select></td>
</tr>
<tr>
<td align="right" valign="top">Message:</td>
<td align="left"><textarea name="message" cols="40" rows="5" id="message"></textarea></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>


And here is the php code:



<?php
$from = $_POST['from'];
$to = $_POST['to'];
$carrier = $_POST['carrier'];
$message = stripslashes($_POST['message']);

if ((empty($from)) || (empty($to)) || (empty($message))) {
echo"Fail";
}

else if ($carrier == "verizon") {
$formatted_number = $to."@vtext.com";
mail("$formatted_number", "TestingText", "$message");

echo"Success";
}

else if ($carrier == "tmobile") {
$formatted_number = $to."@tomomail.net";
mail("$formatted_number", "TestingText", "$message");

echo"Success";
}

else if ($carrier == "sprint") {
$formatted_number = $to."@messaging.sprintpcs.com";
mail("$formatted_number", "TestingText", "$message");

echo"Success";
}

else if ($carrier == "att") {
$formatted_number = $to."@txt.att.net";
mail("$formatted_number", "TestingText", "$message");
echo"Success";
}

else if ($carrier == "virgin") {
$formatted_number = $to."@vmobl.com";
mail("$formatted_number", "TestingText", "$message");

echo"Success";
}
?>


If anyone has any idea of cloaking the hosting servers name. Let me know please.
Thanks all.

Fou-Lu
06-26-2010, 05:29 AM
Do you mean as a default email address?
The third example on the following link shows how to change the from address: http://php.ca/manual/en/function.mail.php
You can also connect to different smtp servers by using custom socketing.
You can clean the script up a little too, the empty function accepts any number of arguments, and use a switch to determine the to address. This will let you call mail only once.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum