Opensourc SMS Gateway Using Gammu and MySQL

gammu_sms1.jpg gammu_sms.jpg gammu_mysql.jpg

The applications of the SMS gateway can be searched and downloaded from the internet. You would be able to found a number of SMS gateway applications from the various platforms.

One of them that will be discussed in this article is Gammu, As we are going to use Gammu application for sms gateway, because apart from we can download free also it’s easy to configure and can be use in both i.e. Windows and Linux. Another reason is to use Gammu is because MySQL can be used. But here we will discuss that how we can setup SMS gateway using Gammu with Linux.
The mobile phone that succeeded in being tried by me is Nokia 3310 and Siemens C35i using Linux platform.

Before installation is done, first read information repeatedly about Gammu here:

Have you gathered the information?
Now let’s gather the requirement to develop the SMS Gateway using Gammu.

Download Gammu.

1. gammu.tar.gz
Download the gammu package from:

# wget

2. Web Server (If you have webserver, don’t ignore this, if not yet then you must install first apache, myslq, php)

3. The Nokia mobile phone 3310 or Siemens C35i. For other mobiles phone please read again:

Gammu supports various types of the mobile phones. How come? look this: Gammu currently supports: majority of Nokia phones from DCT3 generation with Nokia operating system – for example Nokia 3210, 3310, 3315, 3410, 5110, 5130, 6110, 6510, 6610, 7210, 8310
Many AT devices – for example many Siemens, Sony Ericsson, Nokia, Alcatel models, Alcatel from BE5/BF5/BH4 generation – for example 501, 511, 512, also some functions with OBEX and Symbian devices

4. The Serial cable for the mobile phone

If you have successfully downloaded gammu.tar.gz, please extract it:

#tar xvfz gammu.tar.gz

After extracted automatically you will find the folder gammu-1.08.00, now enter into the extracted folder.

#cd gammu-1.08.00

Before installation make a custom read README, INSTALL, etc.

#. /configure


Here must be paid attention by you whether being that error or not if the error occurs that means a significant library mysql you are still being more incomplete, usually an error that appear was found when MySql doesn’t support the gammu. (his installation process repeatedly try to find the mysql library which is needed)

#make shared
#make install
#make installshared

Further it’s necessary for you to upgrade the “library”

# vi/etc/
Add the library link /usr/local/lib to file, once you have done upgrade the library:


Note: If you did not find any error to this stage means you have successfully installed the Gammu sms Gateway.

Now tried to enter again into the folder where you extracted gammu.tar.gz and copy the available files in folder /docs/example/config/* here you will find 3 files by the name of gammurc, mysql.sql, smsdrc and gammurc.

Copy the gammurc and smsdrc into the /etc directory

#cp gammurc smsdrc /etc/

Further search edited file like this:

port = /dev/ttyS0 #if you are using COM2 then substitute it with ttyS1
#model = 6110 #model of mobile phone was ignored by you, because it doesn’t need often to mention the phone model.
connection = fbus #With Nokia mobile phone connection should be fbus if you used the Siemens mobile phone then substitute the fbus with at19200
#synchronizetime = yes
#logfile = gammulog
#logformat = textall
#use locking = yes
#gammuloc = locfile
#startinfo = yes
#gammucoding = utf8
#rsslevel = teststable
#usephonedb = yes

If you are still confused, inside the gammurc file it has the guidance available. If you are lazy to edit the file, then you can get the file from

Now confirm if the data cable and your mobile phone are connected to port COM1 to your computer, if everything is just fine, run the following command.

#gammu –identify

I hope you could see output as being supervised here:

Manufacturer : Nokia
Model : 3310 (NHM-5)
Firmware : 06.33 F (28-11-03)
Hardware : 1012
IMEI : 350835608671298
Original IMEI : 350835608671298
Manufactured : 0802
Product code : 0505201
Simlock 1 : MCC+MNC 00101, opened, user , counter 0
Simlock 2 : GID1 0000, opened, factory, counter 0
Simlock 3 : GID2 0000, opened, factory, counter 0
Simlock 4 : MSIN 0000000001, opened, factory, counter 0
MSID : 830d50880846870ebedd126096
MCU checksum : 9C79

If you got the connection info like above gammu means Gammu detected your mobile phone and now you can continue to the next step.

Now let’s configure that how all the phone’s SMS’s will be kept by MySQL database to put forward on the webpage using php scripts.

OK further bro… our work has almost finished, possibly have some coffee or cigarettes that could disrupted previously hehe…??

Now try to open the file smsdrc that you copied earlier to directory /etc

#vi /etc/smsdrc

PIN = 1234
logfile = smsdlog
commtimeout = 1
sendtimeout = 10

Search and edit the part that you configured in the mysql database:

# ————————- SETTINGS FOR –smsd MYSQL —————————
user = root
password = password_mysql_user
pc = localhost
database = Database_name

Note: The above lines are to make connection with mysql database.

Now enter to the directory /docs/example/config/ and get the file ‘mysql.Sql’, that is a table structure. Now put this file to the database that we are creating in the MySQL database for SMS gateway.

For sms database
#mysqladmin –u root –p create sms

To create tables for gammu grab the file ‘mysql.sql’

#mysql –u root –p <>

Or it can be easier for you if you make Gammu tables through phpadmin.


Once you are finished, you can start the smsd deamon:

#gammu –smsd MYSQL/etc/smsdrc

The Log filename Is “smsdlog”
Press Ctrl+C to stopped the program …

After the issuing above command if output is like above means your SMS gateway is done successfully and you can use it according to your requirements. And all the available sms in your mobile phone will be entered inside the mysql database.

For your further stage is to putting forward your SMS’s to the web which is using php scripts, The required php script can be downloaded from

You must edit the SMS database info in the sms.php file.
If all goes well, now you can open the SMS’s through your favorite browser:


Now what must be done by you??
The smsd service deamon must be running to grab the SMS’s from the phone and you and you could see on the web.

Create a Gammu startup and place it in the directory /usr/local/Bin/#cd/usr/local/bin/


File contents are as follows:
#! /bin/sh
export LANG=da
/usr/local/bin/gam you –smsd MYSQL/etc/smsdrc

After edited that file open /etc/inittab

#vi /etc/inittab

And add the below line in the inittab


Wow… was long enough also, hmmm hopefully did not have the problem ya… now finished your coffee, until you finished developed the SMS Gateway by using Gammu.
If you are having comments and questions, do not hesitate, just feel free to ask.

Be Sociable, Share!

52 Responses to Opensourc SMS Gateway Using Gammu and MySQL

  1. Manan November 22, 2006 at 12:56 pm #

    Hi i wanted to know where i can get the Cable m bus for the communication using Gammu

  2. syedsauds November 27, 2006 at 5:32 pm #

    Well, you should put space between “MYSQL” and “/etc/smsdrc” as mentioned below:

    -bash-3.00# gammu --smsd MYSQL /etc/smsdrc
    Log filename is “smsdlog”
    Press Ctrl+C to stop the program …

    I suggest you should try gammu --identify to check if your phone is identified by gammu or not.

    Some usefull gammu commands:

    # gammu --monitor 1 This command will output information about free and occupied space for SMS, number of calendar entries available, your phone’s battery status, GSM network signal strength, SIM card space utilisation (divided in different categories), additional GSM network status, etc. If you change it to gammu –monitor you can get Gammu to monitor the status continuously, until you hit Ctrl-C on your keyboard.

    # gammu --backup /home/tony/n7110bkp.dat Backup your phone’s data to a file called n7110bkp.dat stored in /home/tony. Unless you append the -yes argument you will get prompted with questions about whether to save data in Unicode format, and which information to backup (SMS, address book entries, calendar notes, logos, ringtones, etc.). The input is case-sensitive. Note: I follow the 8.3 filename convention so I can transfer the backup file to any filesystem without any issues.

    # gammu --restore Information about your backed up data will be displayed for you, along with date and time of backup. At the same time, you get prompted about whether and what to restore from a previously backed up file.

    # gammu --getwapsettings start# stop# On my Nokia 7110i phone, I can use the Internet through a dial-up fax modem and reach WAP pages. This command retrieve the WAP settings stored in your phone. Passwords are passed in cleartext form, so paranoid people should think twice before using this command. However, it’s extremely useful and practical.

    # gammu --nokiagetadc Battery information for Nokia phones.

    # gammu --nokiaselftests Check the general health and status of a Nokia phone. Very useful for testing the status of a purchased used phone. It might be able to help you determine if you should send the phone to a repair shop.
    # gammu --reset SOFT Reboot your phone’s firmware.
    # gammu --reset HARD Reboot your phone completely, and be prepared to enter a PIN code unless there isn’t one configured.

  3. Jayvee November 29, 2006 at 4:00 am #

    Thanks for making a tutorial. I would like ask how if it is possible to automatically start the SMS daemon of Gammu on startup of my Windows PC. If yes, what are the steps? Thanks!

  4. syedsauds November 29, 2006 at 1:41 pm #

    Jayvee, did you install gammu on windows?
    As for as startup concerned simplay create a batch (file.bat) with the put gammu SMS daemon command in it. Then go >> Start >> All programs >> right click on “Startup” here and then open it. Now you can copy your batch file here in startup.
    Let me know if it was an answer for your question regarding Gammu SMS daemon on startup.

  5. Jayvee December 3, 2006 at 10:40 am #

    Thank you very much for your response.Yup, I installed GAMMU on Windows. It was really a big help!

  6. Jayvee December 3, 2006 at 1:44 pm #

    I would like to ask if establishing a remote database connection on a MySQL server deployed using localhost in Gammu (Windows) is possible. If yes, how can i establish such connection?. Thanks!

  7. syedsauds December 3, 2006 at 2:32 pm #

    Just set the host parameter in the gammu configuration file “smsdrc” file to the IP address of the other server. You’ll also need to open the MySQL port (3306) on the other server if it’s closed. Also you would need allow remote user in the MySQL database for remote connection. i hope this helps.
    If you need MySQL remote connection allowing command in MySQL please post your details at in “mobile phones” section.

  8. Jayvee December 4, 2006 at 5:46 am #

    Thank you for always being ready to help others. You’re so great. I will try to contact the webhosting provider of our client and ask the IP address of the server, to open MySQL port 3306 and allow a user to connect remotely. Thanks again!

  9. Harry January 12, 2007 at 6:00 pm #

    Thanks for tutorial. I have questions. How make auto sending SMS to our target number, and the content we grab from MySQL database. It’s like service sms on demand, who someone try to request our data from their phone and automatically our database send it. Thanks before :)

  10. Iban January 19, 2007 at 1:01 pm #

    I have connection with my mobile phone with gammu –identify. I get mysql running with my control center and i have a database called “message” with all the tables shown in mysql.sql file from the docs of gammu. But when i have to execute the command
    #gammu –smsd MYSQL/etc/smsdrc

    i get this error
    Unknown service type (“MYSQL”)

  11. Saud January 24, 2007 at 6:29 pm #

    Harry, for doing that you will have to create a program using your preferred language, and put some sql queries which will grab the data from the database and will auto send the message against the target number the one you specified.

    query example:

    select ID,SenderNumber,TextDecoded from inbox where Processed = ? order by ID

    you can use Java Mail API for sending SMS to the target number

  12. Ade October 20, 2008 at 3:02 pm #

    thanks for your tutorial,
    can you give me tutorial about sms autorespond with gammu, i have conection use sony ericsson k608i

  13. Hardeep December 10, 2008 at 10:26 am #


    i have been desperately trying to make gammu work, if i do gammu –identify it does gives the info, but when i try to send sms with #gammu –sendsms TEXT is show error…… Waiting for network answer error 500, could someone pls help me.


  14. Hardeep December 10, 2008 at 10:28 am #

    pls ready the above command as
    #gammu –sendsms TEXT CELLNO
    Actual Messg

  15. Hardeep December 10, 2008 at 10:56 am #

    I think I have found the answer. After viewing gammu with textall optionI found that my Nokia 6670 always return my operator SMSC
    number as xxxxxxxx while (normally) my S45 return it as +xxxxxxxx.
    Since there is no ‘+’ in the number, gammu will set the number format as
    GNT_UNKNOWN and then sendsms will always fail with +CMS ERROR: 500 as the

    Hope this info will be useful to others

  16. pemmaraju January 3, 2009 at 3:42 am #

    It was a contribution for me you save my life.


  17. pemmaraju January 3, 2009 at 3:43 am #

    It was a gr8 contribution for me, you saved my life

  18. mark January 22, 2009 at 8:18 am #

    hi this was a big help for my current project.. thanks having gammu! and this turial too.

  19. randy January 27, 2009 at 11:26 am #

    gammu is run in localhost.. how about database in other computer..???

  20. admin January 28, 2009 at 11:28 am #

    Randy, ofcourse for that you will have to create sms database on the remote server as following:

    If gammu sms database is on Local machine:
    #mysqladmin –u root –p create sms

    If the gammu sms database is on remote machine:
    #mysqladmin -h –u root –p create sms

    And for database connection you would need to call database from remote server using it’s IP address on port 3306.

    Hope this helps

  21. Rupin February 7, 2009 at 1:38 pm #

    I would like to ask you for more help on the runonrecieve command in the smsdrc file..
    Is there any documentation on this?

  22. Fedlandy February 17, 2009 at 4:41 am #

    I use SE K618i, Ubuntu Linux and LAMPP. Ihave configure gammurc and smsdrc. It works. Gammu has detect my SE K618i. When I use command :

    gammu –smsd MYSQL /etc/smsdrc

    there is no error found. But my MYSQL table inbox always empty.

    Please help me.. thx b4

  23. ali akhbar khan February 17, 2009 at 9:14 am #

    thnx for the tutorial.. really helpful… do you know how to make a function for send to many using php script…

  24. DDF February 25, 2009 at 4:42 pm #

    Great Tutorial,
    but I have the same trouble of Fedlandy (22). I’m using nokia 6680, could you help me
    (us :-D) ???
    Thanks in advance for your reply


  25. Saravana Karthik March 5, 2009 at 3:56 pm #

    My Phone model is Sony Ericsson W580i model…
    i am using Gammu 1.28.0……

    1)how to install Windows vista…
    2)how to configure the Gammu…..
    3)how to compile and Recived SMS to be store on Database…

  26. Dave May 5, 2009 at 7:49 pm #

    Great Tutorial it’s really interesting

    I managed to get gammu work from my Ubuntu command line and then went to install MYSQL and install the PHP script you provided but as I fill in the destination number and message I get the following error..

    Error opening device, you don’t have permissions.
    Warning: Cannot modify header information – headers already sent in /var/www/send-sms.php on line 36

    Any suggestion from where I can set the permissions to access the device?


  27. sebastian May 26, 2009 at 10:56 pm #

    hello frend..
    when I’m using Daemon gammu.
    this syntax could be:

    gammu-smsd -c smsdrc

    I can not use the command to send sms gammu because this modem port occupied by the devil jaja…
    eg when using these commands:

    gammu –identify o enviar sms ej: echo “hola” | gammu sendsms TEXT 156461053

    I get this error:Error opening device. Unknown, busy or no permissions.
    This means you can receive sms but can not send

    The obvious question would be mine. How to use two command at a time?

    This is all thanks ..


  28. seba266 June 1, 2009 at 11:36 pm #

    I was reading the examples of intergammu
    and I have some doubts before practice

    excuse me by my spelling errors i know speak spanish, little english
    maybe we could discuss an interesting topic….

    when I’m using Daemon gammu.
    this syntax could be:

    gammu-smsd -c smsdrc

    I can’t get to use the command to send sms gammu because this modem port is occupied by the daemon jaja…
    eg when using these commands:

    gammu –identify or send sms eg: echo “hello test” | gammu sendsms TEXT number

    I get this error:Error opening device. Unknown, busy or no permissions.
    This means, i can receive sms but can not send.

    The obvious question would be mine. How to use two command at a time?

    how to send and receive sms linked at mysql whithout daemon perhaps?

    ¿Can I send and receive sms without a database attached to a deamon??

    my mail is:

    This is all thanks ..


  29. byzantine June 18, 2009 at 4:18 am #

    “And for database connection you would need to call database from remote server using it’s IP address on port 3306.”

    Hi,my database is other computer (ip. but gammu and the modem in other computer (ip.
    May I know what should I write down in “smsdrc” config file for item “pc = localhost”?
    Thanks a lot for Your Answer..

  30. constantine August 30, 2009 at 8:37 am #

    i install my gsm modem sucessful,but when i run gammu –smsd MYSQL /etc/smsdrc ,return error message:
    Error: SMS daemon is now in separate binary, please use gammu-smsd instead of gammu smsd!

  31. Kancil December 3, 2009 at 7:27 am #

    SMS daemon is now in separate binary…..
    You are most likely using newer version of gammu. Tru to use older version

  32. Hasnat December 15, 2009 at 4:34 pm #

    mysql smsd works fine for me
    but problem is runonreceive
    not executing the script
    checked permissions and stuff
    script itself is just a wget

  33. leen January 11, 2010 at 10:21 am #

    salam.i’m a beginner.i want to install gammu,but after i dload,it’s quite confusing..may i know how to install gammu on window 7?tq for all the info though…

  34. Tachikoma January 27, 2010 at 11:07 pm #

    Hi there… I’m trying to get this to work using a Siemens SX66 that I have. I am running ubuntu, current as of this writing. I installed LAMP stack and that is functioning properly. I installed gammu via apt-get, and it seems to ave installed correctly. But I have a few questions that I have not been able to answer after searching what seems like the only available info on the net for this…
    1. Will this phone work? The Siemens SX-66 is an older HTC phone, pocket PC.
    2. It is connected via USB, so after running lsusb I get this: Bus 003 Device 002: ID 0bb4:0a05 High Tech Computer Corp. PocketPC Sync
    So what do I take from this to modify my gammu config file with?

    I think once I confirm whether or not I can use this device, and then if so, get it properly connected via the gammu config file, I can get going then.

    Thank you in advance for any replies.

  35. dstarlight February 8, 2010 at 4:53 pm #

    brother … i can run gammu daemon at start computer. i use ubuntu … Thx

    still learning
    Ace dstarlight

  36. Enda February 9, 2010 at 4:04 pm #

    I wore se k610i.when run gammu –identify,there are only 5 lines.when starting gammu daemons,response:’unknown service (‘mysql’)…
    Please help me..

  37. arpit rastogi March 9, 2010 at 8:55 am #

    this is such a nice tutorial,i have configured gammu on my ubuntu server and able to send sms from outbox table,but when i connect my phone sony erricson w610i/w610c with ubuntu then all inbox messages goes unknown and i m not able to store messages to inbox table in mysql.

  38. Harshid Joshi June 3, 2010 at 10:52 pm #

    i want a python script that will read incoming sms and display it on screen
    or post it to a localhost site.

    please help me.

  39. kreisa June 29, 2010 at 9:40 pm #


    Hi. Thank you for making this tutorial!
    It helps  a lot!
    I'm just wondering, is it possible to use gammu with

  40. doel July 2, 2010 at 10:33 am #

    i have a problem when type gammu –smsd MYSQL /etc/smsdrc   error : Error: SMS daemon is now in separate binary, please use gammu-smsd instead of gammu smsd!
    Some body help me! thanks

  41. Dipesh Shah July 7, 2010 at 9:16 am #

    I am using gammu with java in ubuntu for an autoreplying system.
    The incoming process is properly.
    for executing the gammu-smsd-inject i am using,
    Process p = Runtime.getRuntime().execute("<gammu-smsd-inject-command>");
    but the sms is not injected in the outbox and the sentitems table..!!
    Please help,
    what could be the solution out of this..?

  42. Sidharth July 7, 2010 at 9:36 am #

    i am hvaing  the same problem as above …..when i type in the command
    "gammu –smsd MYSQL /etc/smsdrc"  
    it show the error : Error: SMS daemon is now in separate binary, please use gammu-smsd instead of gammu smsd!
    probably this may be problem due to the new version of gammu. So, can you please tell me how to set up the sms gateway on the latest version of gammu(1.27)

  43. ivan July 30, 2010 at 3:07 am #

    great tuto…. thank you!

  44. kreisa August 28, 2010 at 11:39 am #

    @ Sidharth

    Try this:
    Create a new database in mysql.
    Open your smsdrc file and set to the following:

    service = mysql
    PIN = 1234
    logfile = smsdlog
    commtimeout = 1
    sendtimeout = 10
    user = root
    password =
    pc = localhost
    database = [insert name of your database here]

    Save it in \Gammu\bin. After that, try running this command on cmd

    gammu -smsd -c smsdrc

    Note: This command will automatically transfer all your SMS to the database, so don’t be surprised if your inbox becomes empty. lol

  45. noobie February 22, 2011 at 5:51 am #

    hi! very informative tutorial. I am wondering if you could help me. It seems that gammu is not executing my runonreceive script.
    Tue 2011/02/22 09:26:50 gammu-smsd[1978]: Starting run on receive: “/path/” 31
    Tue 2011/02/22 09:26:50 gammu-smsd[1556]: Process exited, status=0

  46. Sandeep Samdaria April 8, 2011 at 11:51 pm #

    Is it possible to use databases other than MYSQL for eg DB2(IBM) ?
    pls help…

  47. noobie April 12, 2011 at 6:05 am #

    Yes, it is possible to use other databases. You can use SQL, PSQL, or DBI. Please refer to for more details.:D

  48. Shoaib Hussain May 24, 2011 at 11:05 pm #

    im trying to send long sms, sms is inserted successfully in outbox and outbox_mulipart tables. But gammu failed to send sms. when i check log file, i found following…. please save my life.

    Wed 2011/05/25 01:53:50 gammu-smsd[8412]: SMS sent on device: “com44:” status=-1, reference=-1
    Wed 2011/05/25 01:53:50 gammu-smsd[8412]: Error getting send status of message: Unknown error. (UNKNOWN[27])
    Wed 2011/05/25 01:53:50 gammu-smsd[8412]: Execute SQL: INSERT INTO sentitems (CreatorID,ID,SequencePosition,Status,SendingDateTime, SMSCNumber, TPMR, SenderID,Text,DestinationNumber,Coding,UDH,Class,TextDecoded,InsertIntoDB,RelativeValidity) VALUES (‘Gammu 1.29.0’, ‘2’, 1, ‘SendingError’, NOW(), ‘+923330005150’, -1, ‘Nomads-3’, ‘002200610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061006100610061’, ‘03214656163’, ‘Default_No_Compression’, ‘050003BB0201’, -1, ‘\”aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa’, ‘2011-05-25 01:53:02’, 255)

  49. khalid rajabu February 24, 2012 at 11:40 pm #

    sorry am hardly trying to ready and understand Gammu, on my way i saw some script wrote by you i don’t know when but i think you are a right person to whom i can get the answer of this question…..If i developed my website and launched with added functionality of sending and receiving message by using Gammu, so the modem used for connection it will be needed all the time at the pc used for development? SORRY AM THE BEGINNER…I KNOW NOTHING ABOUT GAMMU.plz i need your help!!!

  50. fred September 4, 2012 at 7:54 pm #

    I am student in Africa and I have a project to give to the school about the instant dissemination of several messages (500) using the interconnected Gammu-maaw gateway to mysql. MySQL is the database which are recorded the names and contacts of the students.
    I have there idea of the script to write to instantly send the same message to all the number of students registered in the mysql database. the messages will be sent through a modem GSM (mobile phone).
    Help me if you can.
    Thank you in advance.

  51. admin September 4, 2012 at 9:44 pm #

    Fred, You can do this through a perl or shell script easily, what you need to do is fetch the each number from the database table with 2 or 3 second wait. You can get store these students numbers in a table’s coulmn and grab them with query and send them through script. You didn’t mention what phone or modem you will be using?


  52. fred September 6, 2012 at 9:39 pm #

    I have a serious problem during the sending of the sms command line. I have a samsung galaxy GT-I9000 S1.
    I used the command: echo “message”. gammu – sendsms TEXT 7702XXXXX
    What to do?

Leave a Reply