First of all, to
know how to send an
SMS using Email2SMS application you must understand what makes
this app:
Basically this application turn an email into one or more sms.
What made this application?
-
After installing the application, its opening
and will ask you to add or select a google account
from which it read
mails.
-
From the settings menu
you can set the repeat interval, ie how many minutes
after application to read emails seeking
patterns set by
you in the application interface
-
For each template you can set:
o
Inof-
more information about template (may or may not be
set)
o
Active - can have two active
or inactive state. If pattern
is not active application will not seek in your email (email set when the application run for the first time or later) for that template.
o
From - email box from receiving emails
with phone numbers and text to be sent by SMS
o
Subject -
the subject of the email (may or may not be
set). If not set
it to take all mails
received at the address set
above.
Application
workflow is:
The database server, where customers
have their phone numbers,
(for MSSQL) send
an email to the email address set (email set when the
application run for the first time or later) whose content should be
formatted like the
below:
<phoneNo>
<text>
078999999,
078999998, 078999997</phoneNo>
<text>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam
tincidunt mauris eu risus. Vestibulum
auctor dapibus neque.</text>
An example of a query
whose result will
be emailed might be:
SELECT '<phoneNo>'
AS EmailBody
UNION ALL
SELECT phoneNo+', ' AS EmailBody FROM customer
UNION ALL
SELECT '</phoneNo>'AS EmailBody
UNION ALL
SELECT '<text>'
AS EmailBody
UNION ALL
SELECT 'Lorem ipsum
dolor sit amet, consectetuer adipiscing elit.' AS
EmailBody
UNION ALL
SELECT '</text>'
AS EmailBody
o We can send email when
an event happens in
a trigger or not necessarily, such as ordering products or services to be processed (to see
how to set MSSQL you
can see http://www.codeproject.com/Articles/485124/Configuring-Database-Mail-in-SQL-Server )
o If the database is
MySQL can be set in
the operating system scheduler (crontab in
Linux) to run a
php script say,
to verify the
existence of a set
time for new notifications to be
sent emails. An example would be
http://www.ssiddique.info/php-code-to-send-email-from-mysql-database.html
-
So emails arrive to mail server
from Google, Gmail, where they will be read (emails marked as
unread) by the Email2SMS
application, according to set
filters for each
template in hand, sending sms for every phone number in the email found.
-
After
reading emails and sending SMS is successful they are marked as read
on gmail server for the next time the
application to ignore emails
already processed.
An example of sending emails from MYSQL is:
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQLProfile',
@recipients = 'yourEmail@gmail.com', --in this email account Email2sms app will -- search form a new email and filer as
you set on the application
@query = 'SELECT '''<phoneNo>''' AS EmailBody
UNION ALL
SELECT phoneNo+''', ''' AS EmailBody FROM customer
UNION ALL
SELECT '''</phoneNo>''' AS EmailBody
UNION ALL
SELECT '''<text>'''
AS EmailBody
UNION ALL
SELECT '''Your order has been processed.
Within one day you will be contacted by the courier to
deliver you order.''' AS EmailBody
UNION ALL
SELECT '''</text>'''
AS EmailBody',
@subject =
'Order processed';
<?php
$dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $dbname = 'dbName'; $today = date("m\/d\/Y"); // todays system date $date_ = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")); // adding specific number of days to date to get reminder of subscription expiration. $tomorrow = date("m/d/Y", $date_); //formatting the date time according to your database format $Renewal = (string) $tomorrow; $ordernumber = ""; $conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$conn) {
die('Failed to connect to server: ' . mysql_error());
}mysql_select_db($dbname);$sql = "SELECT '<phoneNo>' AS EmailBody
UNION ALL
SELECT phoneNo+', ' AS EmailBody FROM customer
UNION ALL
SELECT '</phoneNo>' AS EmailBody
UNION ALL
SELECT '<text>' AS EmailBody
UNION ALL
SELECT 'Your order has been processed. Within one day you will be contacted by the courier to deliver you order.' AS EmailBody
UNION ALL
SELECT '</text>' AS EmailBody"; $result = mysql_query($sql); $email = "from@domain.com"; $emailto = "to@domain.com"; $emailcc = "cc@domain.com"; $emailcc = ""; $subject = "email2sms"; $headers = "From: $email" . "\r\n" . "CC: $emailcc";
while ($row = mysql_fetch_array($result)) {$body .= " \n " . $row['EmailBody'] . "\n";}// send email if (mysql_num_rows($result) > 0) {
$send = mail($emailto, $subject . ' ' . $ordernumber, $body, $headers);
}mysql_close($conn);?>
