RunCodes
Programming & Tech

How to Send Free SMS using PHP?[With Source Code]

4 11,538

As you all know guyz, the era that we are living is an era of internet, so everyone is hanging on their PC all the time. Everyday we are sending some SMS to our friends in order to inform something to them. So, if there is some method that can send SMS for free, everyone gonna use that method and loved it. Today, in this tutorial we are gonna discuss about that method using PHP. And also if you wanna send the message to your friends without displaying your number and name, this tutorial is for you! sometime we are in the mode of cracking jokes and wanna fool your friends or sending some threatening message(only for entertainment purpose otherwise it will be illegal) you can use this method. This method of sending SMS is called email2sms Method.

“This tutorial may be very useful for those who want to integrate SMS features in their project which is developed in PHP”.

For sending SMS using email2sms approach: you have to do three task:

1.    Selecting Carrier

2.    Configurating Mail Routing Software

3.    Writing PHP Script

we are selecting txtlocal as our carrier. So, All you have do is go to http://www.txtlocal.co.uk and there you need to create one account. after creating account. (you need to fill up some of your information and txtlocal will send you a verification email into your email and verify your account [watch the video for detail]) you have to hover your mouse over setting menu and click check box of active emaill2sms.

After doing this, you need to download this software having the name sendmail click here and copy the file inside your localhost root folder in my case c://wamp64/sendmail and then open that sendmail and find sendmail.ini file and open this file with notepad and  then scroll down and find following term:

auth_username=
auth_password=
force_sender=
hostname=
smtp_server=
smtp_port=

Write your gmail in the place of auth_username, password to auth_password, again your gmail in force_sender, and localhost in hostname same as following:
[sociallocker]

auth_username=example@example.com //your gmail account
auth_password= ******* //your email password
force_sender=  example@example.com   //your gmail account
hostname=localhost
smtp_server=smtp.gmail.com
smtp_port=587

After completing this save that file.

Again open php.ini file from your server application. in case of wampserver, click the green icon of wamp server from system tray, hover over PHP and then choose php.ini file, open that file in notepad and find mail function. i.e. [mail function] inside this [mail function] find the following parameters:

SMTP=
smtp_port=
sendmail_from =
sendmail_path =

set the following value to them:

SMTP= smtp.gmail.com
smtp_port=587
sendmail_from =example@example.com // your gmail account
sendmail_path =”C:\wamp64\sendmail\sendmail.exe -t”

and save this php.ini file for more details you need to watch this video: CLICK HERE

After doing this, you complete the task of selecting your carrier and configurating your mail routing software. we need to configure mail routing software because we send SMS using email. Now write the following piece of code in any text editor software, i am using Dreamweaver CC and saved this php file in .php extension in your localhost and run (Note: your PHP file will not execute in the same way you run your html file, because PHP is server side scripting language so you need to have any server application to run this file.  watch this video to configure site and testing server in Dreamweaver CC: https://youtu.be/L4ex3S8BVCo or read here: click here)


<!doctype html>
<?php if(isset($_POST['send'])){ 
$from = $_POST['femail']; 
$phoneno = $_POST['phoneno']; 
$message = $_POST['message']; 
$carrier = $_POST['carrier']; 
if(empty($from)){ 
echo("enter the email");
 exit(); 
}else if(empty($phoneno)){ 
echo("enter the phone no"); 
exit(); 
} elseif(empty($carrier)){
echo("enter the specific carrier"); 
exit(); 
} elseif(empty($message)){ 
echo("enter the message"); 
exit(); }else{ 
$message = wordwrap($message, 70); 
$header = $from; 
$subject = 'from submission'; 
$to = $phoneno.'@'.$carrier; 
$result = mail($to, $subject, $message, $header); 
echo("message sent to".$to); 
} 
} 
?>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="smsone.php" method="post">
<table align="center">
<tr>
<td>From:</td>
<td><input type="email" name="femail" placeholder="example@example.com"</td>
</tr>
<tr>
<td>Phone Number:</td>
<td><input type="text" name="phoneno" placeholder="enter 10 digit phoneno with country code"</td>
</tr>
<tr>
<td>carrier:</td>
<td><input type="text" name="carrier" placeholder="enter the carrier. ex: vtext.com"</td>
</tr>
<tr>
td>Message:</td>
<td><textarea rows="6" cols="50" name="message"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="send" name="send"</td>
</tr>
</table>
</form>
</body>
</html>

May be after sending 10 SMS your credit will be finished! but don’t be sad, you can send more and more SMS but you need to create another account with another email account in www.txtlocal.co.uk! that’s it. you may not be that much happy to hear this (sending only 10 SMS) but don’t forget you are able to send these 10 SMS for free and also there is one line “To get something, you must lose something”. it means you have to spend some time in creating account in txtlocal.co.uk in order to send free SMS.

[/sociallocker]

Finally, if you guyz think, this is awesome tutorial and help you in some extend please share this tutorials with your all friend so that they can know about this method of sending SMS!

For more details watch the video:

 

 

Show Comments (4)