PHP: Mail Sending

We will see here the simple mail sending format in PHP,

Before sending mail need to enble and modify the below line PHP.ini file

; For Win32 only.
smtp_port = 25

; For Win32 only.
sendmail_from =

the code to send a mail is,

mail(“”,”test subject”,”test message”,””);


The below code will explain the convertion format from number to Word Equivalent. For example the the number is taken here 9999999 and the word equivalent is, Nine Million Nine Hundred and Ninety-Nine Thousand Nine Hundred and Ninety-Nine,

The below is code,


function convert_number($number)
if (($number < 0) || ($number > 999999999))
throw new Exception("Number is out of range");

$Gn = floor($number / 1000000); /* Millions (giga) */
$number -= $Gn * 1000000;
$kn = floor($number / 1000); /* Thousands (kilo) */
$number -= $kn * 1000;
$Hn = floor($number / 100); /* Hundreds (hecto) */
$number -= $Hn * 100;
$Dn = floor($number / 10); /* Tens (deca) */
$n = $number % 10; /* Ones */

$res = "";

if ($Gn)
$res .= convert_number($Gn) . " Million";

if ($kn)
$res .= (empty($res) ? "" : " ") .
convert_number($kn) . " Thousand";

if ($Hn)
$res .= (empty($res) ? "" : " ") .
convert_number($Hn) . " Hundred";

$ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen",
$tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
"Seventy", "Eigthy", "Ninety");

if ($Dn || $n)
if (!empty($res))
$res .= " and ";

if ($Dn < 2)
$res .= $ones[$Dn * 10 + $n];
$res .= $tens[$Dn];

if ($n)
$res .= "-" . $ones[$n];

if (empty($res))
$res = "zero";

return $res;

$cheque_amt = 9999999;
echo "

ExtJS Tips for GridPanel Row – Marking, Colouring, Focusing & Special Key Event Firing

ExtJs, a powerful library for developing web application. Bit complex to learn & start with, but once you practice some examples it becomes easy. You need to have good knowledge in Object Oriented Programming to extend & implement your own features or controls, and to see power of JavaScript & ExtJS. Working with ExtJs is really interesting! Here listing some hints that may help you in your programming. Array-Grid example that comes with ext-2.0.2 is modified to demonstrate the same.

  1. Focusing grid on load to activate down & up arrows
  2. Colouring grid rows based on some criteria
  3. Key events (especially Navigation keys) usage in grid with Internet Explorer (IE7) & Firefox
  4. Marking selected grid row with some icon / text color change

The code in action can be seen at ExtJs Array Grid Sample
Same can be downloaded from: ExtJs Array Grid Sample – Source Code (~311 KB since extjs images & base scripts).
Main files that are modified: array-grid.html, array-grid.js & examples.css.

1. To focus the grid.

After rendering the grid


2. Row colouring

Mainly this is CSS twist with use of getRowClass to change the text color of whole row.

grid.getView().getRowClass = function(record, index){
return (<0.7 ? (<0.5 ? (<0.2 ? 'red-row' : 'green-row') : 'blue-row') : '');

3. Key Events

While working GridPanel, along with focusing the first row we were in a need of implementing the making of rows selected by user with Left Arrow & Right Arrow, as well they can navigate up & down with Up Arrow & Down Arrow.

The below code works partially in IE. It won’t capture navigational (along with arrows, page up, page down, home, end) keys & some special keyevents. But it works perfect in Firefox.

grid.on('keypress', function(e){

Whereas ‘keydown’ keyboard event works perfectly in both browsers for all keys. But the e.getKey() in IE won’t get the key code for navigational keys & some special keys. So need to change that to normal “e.keyCode”.

There maybe some property to set in ExtJS like in KeyNav -> forceKeyDown to true to make the getKey & keypress work in IE & FF. Not sure where & how exactly, but now the above quick solution worked without any problem.

grid.on('keydown', function(e){

4. Marking Selected Grid Rows

In order to mark the selected rows, experimented on task example provided in ExtJs with Google Gears. Before experimenting used the data.columnName = ‘some value’ to set & gridview’s refresh() to apply. But at a time only a row used to change & previous selected rows used to change back.

In this same Array-Grid example added a new boolean value ‘true – flase’ column as first column ‘Status’. Added a ‘renderer’ to this new column, which sets a css class with empty box image if vale is false / tick mark if value true. Also 2 events, one mouse click and the other keydown event to grid to change the value of particular data element. Here the tricky point is if we change the value of it in store record, then automatically the respective CSS will be applied to it through its ‘renderer’. As said before if we change the ‘data’ in grid it won’t work, we need to apply the change of value in record of the store.

The code & css is

grid.on('keydown', function(e){
if(e.keyCode == 37){
var rec = grid.getSelectionModel().getSelected();
rec.set('status', false);
}else if(e.keyCode == 39){
var rec = grid.getSelectionModel().getSelected();
rec.set('status', true);

grid.on(‘rowclick’, function(grid, rowIndex, e){
var rec =;
rec.set(‘status’, !rec.get(‘status’));

.task-completed, .task-check-over {
background: transparent url(../images/check.gif) no-repeat center -16px;
.task-check-over {
background: transparent url(../images/check.gif) no-repeat center -32px;

Same can be downloaded from: ExtJs Array Grid Sample – Source Code (~311 KB since extjs images & base scripts).
Main files that are modified: array-grid.html, array-grid.js & examples.css.

Core JavaScript

JavaScript is a scripting language widely used for client-side web development. It was the originating dialect of the ECMAScript standard. It is a dynamic, weakly typed, prototype-based language with first-class functions. JavaScript was influenced by many languages and was designed to look like Java, but be easier for non-programmers to work with.

JavaScript, despite the name, is essentially unrelated to the Java programming language, although both have the common C syntax, and JavaScript copies many Java names and naming conventions. The language’s name is the result of a co-marketing deal between Netscape and Sun, in exchange for Netscape bundling Sun’s Java runtime with their then-dominant browser. The key design principles within JavaScript are inherited from the Self and Scheme programming languages.

The more information on Javascript is available from the Javascript Bible is available as a PDF to download,

Core Javascript Bible

Zend Certification

Zend Certifications set the industry standard for PHP certifications, recognizing outstanding expertise and delivering a measure of distinction for PHP 5 and Zend Framework developers. Utilizing exam topics specified by a neutral board of top PHP experts and community members worldwide, the Zend PHP 5 Certification and Zend Framework Certification ensure Zend Certified Engineers a clear advantage.

Zend Certification

Zend Certification


The test Certification form and the venue detail can get from the below link 

You can download  The Zend Certification Practice Test Book fom the below link.

zend PHP Certification Practice Test Book

N Level Menu

In PHP, creating the new level menu as per the menu table specified list of sub menus dynamically.
The N level menu will illustrate here, the menu generation on menu -> Sub-Menu1->Sub-Menu2-> Items hierarchy .

The table structure for the n-level menu looks as below,

Please Click Here to download the code

id number(6)
parent_id number(6)
Name Varchar(25)
active binary(1)

Useful Queries

we will see some use ful queries on MySQL,

1.Finding 2nd Maximum Number,

“select column A from tableA order by columnA desc limit 1,1”

2.Finding 2nd Minimum Number,

“select column A from tableA order by columnA asc limit 1,1”

3.Finding Saturday and Sunday in a year, in below code you can a procedure to extract saturday and sunday in a year,



CREATE DEFINER=`root`@`localhost` PROCEDURE `testa`()
declare l_functionReturnDate datetime;
declare i_TRFE_Start_Dt datetime;
declare i_TRFE_End_Dt datetime;
declare TripDate datetime;
declare l_curMonth varchar(2);
declare l_curyear varchar(4);
declare date_t char(10);
set i_TRFE_Start_Dt=now();
set i_TRFE_End_Dt=’2009-03-28 12:51:01′;
while i_TRFE_Start_Dt < i_TRFE_End_Dt do
set l_curyear=substring(i_TRFE_Start_Dt,1,4);

set l_curMonth=month(i_TRFE_Start_Dt);

set date_t=day(i_TRFE_Start_Dt);

set l_functionReturnDate=concat(l_curyear,’-‘,l_curMonth,’-‘,date_t);
select fc_GetWeekdayDate (l_functionReturnDate,’Saturday’,1);
set i_TRFE_Start_Dt = date_add(i_TRFE_Start_Dt, interval 7

end while;




DROP FUNCTION IF EXISTS `test`.`fn_GetWeekdayDate`$$

CREATE DEFINER=`root`@`localhost` FUNCTION `fn_GetWeekdayDate`(
TheDate  Datetime,
DayName  varchar(10),
DayNum   Tinyint
) RETURNS datetime
DECLARE InitialDate     Datetime;
DECLARE ReturnDate      Datetime;
DECLARE Dow int;

SET InitialDate =

CASE WHEN Date_Format(TheDate, ‘%W’) = DayName THEN TheDate

WHEN Date_Format(Date_Add(TheDate, INTERVAL 1 DAY), ‘%W’) =

DayName THEN Date_Add(TheDate, INTERVAL 1 DAY)
WHEN Date_Format(Date_Add(TheDate, INTERVAL 2 DAY), ‘%W’) =

DayName THEN Date_Add(TheDate, INTERVAL 2 DAY)
WHEN Date_Format(Date_Add(TheDate, INTERVAL 3 DAY), ‘%W’) =

DayName THEN Date_Add(TheDate, INTERVAL 3 DAY)
WHEN Date_Format(Date_Add(TheDate, INTERVAL 4 DAY), ‘%W’) =

DayName THEN Date_Add(TheDate, INTERVAL 4 DAY)
WHEN Date_Format(Date_Add(TheDate, INTERVAL 5 DAY), ‘%W’) =

DayName THEN Date_Add(TheDate, INTERVAL 5 DAY)
WHEN Date_Format(Date_Add(TheDate, INTERVAL 6 DAY), ‘%W’) =

DayName THEN Date_Add(TheDate, INTERVAL 6 DAY)
ELSE TheDate

SET ReturnDate = CASE WHEN DayNum IS NULL or DayNum IN (0,1) Then


Date_Add(InitialDate, INTERVAL (7*(DayNum-1)) DAY)

/* uncomment this if you want to return null instead
of allowing crossover months

SET ReturnDate = CASE WHEN Month(TheDate) = Month(ReturnDate) THEN


RETURN ReturnDate;


ExtJs 2.2

Ext JS is a cross-browser JavaScript library for building rich internet applications.

  • High performance, customizable UI widgets
  • Well designed, documented and extensible Component model
  • Commercial and Open Source licenses available


PHP PDF upload

In this topic will see the PDF Creation and sent a mail,for creating a PDF file need to include the fpdf.php. The file has all the parameter to generate the PDF file.
As seen below,


while sending Mail these lines should follow,

$headers .= “\nMIME-Version: 1.0\n” .
“Content-Type: multipart/mixed;\n” .
” boundary=\”{$mime_boundary}\””;

$message = “This is a multi-part message in MIME format.\n\n” .
“–{$mime_boundary}\n” .
“Content-Type: text/plain; charset=\”iso-8859-1\”\n” .
“Content-Transfer-Encoding: 7bit\n\n” .
$message . “\n\n”;

Please Click here to download the File.


Wampserver is the collection of  Apache,MySQL and PHP  product to develop web based application. The Wampserver  behave as a server to host web application and communicate thorugh the world wide.

The Wampserver lastest version can be downloaded from the below site as FREE.



« Older entries