Tag Archives: Software Development

PHP Mail Function

Send Mail in PHP

PHP provides inbuilt function known as mail() function which allow you to send mail directly from your program. This function returns TRUE on success and FALSE when failed. Mail function accept 5 parameters like to, subject, message, headers and  extra parameters.

Syntax
mail(to,subject,message,headers,parameters)
Name Required Description
to Yes Mail Address of the receiver or receivers
subject Yes Subject of the mail content.
message Yes Mail message. This can either be plain text or HTML formatted mail.
headers No Additional headers can be From, Cc, and Bcc etc.
parameters No Additional parameter to the send mail program.

PHP Simple Mail Function

The following example will send simple text mail.

<?php
$to = "receiver@domain.com";
$subject = "This is a test mail";
$message = "Hi! This is a simple text mail to test";
$from = "sender@a2zwebhelp.com";
$headers = "From:" . $from;
$result = mail($to,$subject,$message,$headers);
if($result==true){
   echo "Mail Sent successfully.";
}
?>

PHP Send Mail With CC and BCC

<?php
$to = "receiver@domain.com";
$cc = "CCto@domain.com";
$bcc = "BCCto@domain.com";
$subject = "This is a test mail with CC and BCC";
$message = "Hi! This is a simple text mail to test with CC and BCC";
$from = "sender@a2zwebhelp.com";
$headers = "From:" . $from . "\r\n";
$headers .= "CC:" . $cc . "\r\n";
$headers .= "BCC:" . $bcc. "\r\n";
$result = mail($to,$subject,$message,$headers);
if($result==true){
   echo "Mail Sent successfully.";
}
?>

PHP Send HTML Mail

<?php
$to = "receiver@domain.com";
$cc = "CCto@domain.com";
$bcc = "BCCto@domain.com";
$subject = "This is a test mail with CC and BCC";
$from = "sender@a2zwebhelp.com";
$message = "<table border="0" width="100%" cellspacing="0" cellpadding="0" 
style="font-family: Verdana; font-size: 8pt">
<tr>
<td colspan="2" align="center" height="40"><b>Simple HTML Mail</b></td>
</tr>
<tr>
<td height="25" width="10%">&nbsp;</td>
<td height="25">Mail content goes here. </td>
</tr>
<tr>
<td height="25" width="10%">&nbsp;</td>
<td height="25">Mail second line goes here.</td>
</tr>
</table>";
// Set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers .= "From:" . $from . "\r\n";
$headers .= "CC:" . $cc . "\r\n";
$headers .= "BCC:" . $bcc. "\r\n";
$result = mail($to,$subject,$message,$headers);
if($result==true){
   echo "Mail Sent successfully.";
}
?>

Send mail with attachment

Click here to know how to send mail with attachment.

PHP Array

Introduction to Array

When creating long, complex programs, it sometimes becomes difficult to access certain elements in a program. for example there is a limitation for using variables in a program: when you declare a variable, you can assign only one value to it. In certain case , you may want to declare hundreds of variables and it may not be possible to remember each and every variable and use it. Array help to accomplish this. An array is a special kind of variable that unlike conventional variables, can storemultiple values that are indexed. To understand this definition let it split it into three parts:.
– An array is a special kind of variable because it is primarily use for strong values.
– Unlike conventional variables, array can store multiple values without any limitation.
– Each value that is assigned to an array is accessed using an index in the form of a number or a string.

Features of Arrays

There are a few underlying features of array that help qualify them as one of the most important elements in any complex program.
– Any number of values can be stored in a single array.
– The value stored in an array can be numeric or string.
– After the value are stored in the array, they can be extracted from it at any given time.
– Arrays enhance the scope and flexibility of a program by allowing data to be accessed easily.
– Array organize complex datastructure that are related in some way.
– It is possible to add values to an array after it is created. which is not possible in case of a variable.
– Values in an array can be retrieved sequentially and randomly.

CREATING A SIMPLE ARRAY

Creating an array is as simple as creating a variable. The only difference is that its main purpose is to hold multiple related values in the same place. consider the fallowing example

<?php
     $week[] = "Sunday";
     $week[] = "Monday";
     $week[] = "Tuesday"; /* And So on */  
?>

Declaring an array by using the array () function

<?php
  $week = array("Sunday", "Monday", "Tuesday","etc..");
?>

ASSOCIATIVE ARRAYS

Arrays that are indexed by using strings are called associative arrays. When you use them, you specified a string instead of number within the square brackets.

<?php
   $student[Name] = "Rishi";
   $student[Age] = "8";
   $student[Game] = "Chess";
?>

OR

<?php
   $student = array(Name=>"Rishi", Age=>"8", Game=>"Chess");
?>

MULTIDIMENSIONAL ARRAYS

As discuss earlier, array can store numbers as well as names. They can also store other arrays. Sucharrays are multidimensional arrays or an array of arrays.

<?php
 $student = array(
 array( Name=>"Rishi", Age=>"8", Game=>"Chess"),
 array( Name=>"Sambit", Age=>"9", Game=>"Chess"),
 array( Name=>"Rupal", Age=>"10", Game=>"Chess"),   
);

echo $student[1][Age];
?>

Output: 9;

Looping through arrays

Another method of accessing the elements in an array and displaying them is by looping. You can use the foreach statement to loop through enumerated, associative and multidimensional arrays.

Looping through an enumerated array

As discuss earlier, the foreach statement comes in handy when looping through an enumerated array. Consider the fallowing example

<?php
foreach ($array as $val){
  echo "My Value=".$val ."<br/>";
}
?>

Looping through an associative array

The foreach statement is also used for looping through an associative arrays, but there is a slight change in the way you use it. You would need to specified the key as well as the value of an element to access a particular element. consider an example

<?php
foreach ($array as $key =>$val){
  echo " $key = $val <br/>";
}
?>

Displaying a multidimensional array

After learning how to loop through enumerated arrays and associative arrays, you might want toknow how to loop through a multidimensional arrays. You can combine your knowledge to looping through enumerated and associative arrays to accomplish this.

<?php
 $student = array(
 array( Name=>"Rishi", Age=>"8", Game=>"Chess"),
 array( Name=>"Sambit", Age=>"9", Game=>"Chess"),
 array( Name=>"Rupal", Age=>"10", Game=>"Chess"),   
);
foreach($student as $st){
 foreach($st as $key => $val){
   echo "$key = $val"."<br/>";
  }
 echo "<hr>";
}
?>

Output:
Name = Rishi
Age = 8
Game = Chess
-------------------------------------
Name = Sambit
Age = 9
Game = Chess
--------------------------------------
Name = Rupal
Age = 10
Game = Chess

PHP Loops

Introduction to Loops in PHP

Using Loops in PHP

Loops are an vital part of a programming language. Typically the need to use loops in a program occur when you want to execute a piece of code repeatedly until a desired condition is achieved. There are many control structures that can be use to implement looping in a program.

The While loop

The while loop is one is the simplest looping control structure in PHP. When you specify a conditionand a code block along with the while loop, the code block is repeatedly execute until the conditionbecomes false.

<?php
$a = 1;
while ($a <= 10){
  echo $a ."<br/>";
}
?>

The for loop

The for loop is similar to the while loop and can achieve the same result. It is use to evaluate a set ofconditional expression at the beginning of each loop. The for loop is one of the most complex loop in PHP.

<?php
for ($a=1; $a <=10 ; $a++){
  echo $a ."<br/>";
}
?>

Breaking a loop

Sometimes, you might want to break a loop before it complete execution .The break statement can do this.

<?php
for ($a=1; $a <=10 ; $a++){
echo $a ."<br/>";
  if($a==5){
    break;
  }
}
?>

The continue statement

The continue statement is the reverse  the break statement, doesn’t breaks a loop. When you break a loop the loop with the break statement, you can’t check for the same condition again. The continue statement just skip the specific iteration and doesn’t cause the loop to end.

<?php
for ($i = 0; $i < 5; ++$i) {
if ($i == 2)
continue
  echo $i;
}
?>

The output will be: 2.

Nesting loops

Nesting loops are a way to use a loop statement within another statement. for example, if you have a loop x, and have another loop y in the loop y in the loop x, the loop y will be executed x*y.

<?php
for ($a =10; $a <= 15; $a++){
    echo "First Loop <br/>";
       for ($b = 5; $b < 10; $b++){
           echo "Second Loop <br/>";
       }
}
?>

HTML Video

Play Video in HTML Page

You can add audio or video to your html page. Either you can add video from www.youtube.com or you can add you own video by uploading the same to your own web server. But it is a bit tricky to show videos in your web page, and it is a little complicated to make it works in all browser.

Browser Supported Video Formats:

File Format
.swf or .flv Flash
.mov QuickTime
.rm or .ram Real Video
.avi AVI
.wmv WMV
.mpg or .mpeg MPEG
.mp4 Mpeg-4

Play Flash File in HTML Page

<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" 
id="obj1" border="0" width="160" height="160">
<param name="movie" value="myfile.swf">
<param name="quality" value="High">
<param name="wmode" value="transparent">
<embed src="myfile.swf" 
type="application/x-shockwave-flash" 
name="obj1" width="160" height="160" 
quality="High" wmode="transparent"></object>

Play QuickTime in HTML Page

<embed src="mymovie.mov" width="320" height="252" 
autoplay="true" controller="true" loop="false" 
pluginspage="http://www.apple.com/quicktime/">

Play RealVideo in HTML Page

<object id="id1" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" 
height="240" width="320">
<param name="controls" value="imagewindow">
<param name="autostart" value="true">
<param name="src" value="myvideo.rm">
<embed height="240" width="320" controls="imagewindow" src="myvideo.rm" 
type="audio/x-pn-realaudio-plugin" autostart=true>
</object>

Play MPEG Video in HTML Page

<embed src="myfile.mpeg" autostart="false" />

Play Youtube Video in HTML Page

<iframe width="420" height="315" 
src="http://www.youtube.com/embed/p9KjdYJ_gcc" 
frameborder="0" allowfullscreen></iframe>
<object width="420" height="315">
<param name="movie" 
value="http://www.youtube.com/v/p9KjdYJ_gcc?version=3&amp;hl=en_US">
</param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/p9KjdYJ_gcc?version=3&amp;hl=en_US" 
type="application/x-shockwave-flash" width="420" height="315" 
allowscriptaccess="always" allowfullscreen="true"></embed>
</object>

 

Enterprise Customized Software

“We always ready to take challenges in giving customized solutions  .”

SOFTWARE DEVELOPMENT

Software is not useful until it fulfills the end requirements. Customization thus is empirical aspect of today’s business world. Customization helps the client to achieve what is required. Client being the end user knows what is actually required. A precise communication with client is essential for customization of software.

Continue reading