Send emails using PHP

In PHP there is a function called “mail” for send emails from our web applications. To use this this function, we have to do some configurations in php.ini file of our web server. If you are using PHP-equipped web host, you don’t need to worry about this mail function setup configuration because all required configurations are done by the hosting providers.


Setting up mail function in PHP


step 1> Goto “php.ini” file in your web server.

step 2> Find “[mail function]” part in the php.ini file.

step 3 for window mail server> Give the mail servers address to “SMTP”, give the port of the SMTP to “smtp_port” (default is 25) and set “sendmail_from” to sender’s email address.


[mail function]


smtp_port = 25

sendmail_from = you@yourdomain

step 3 for unix mail server> Give the path of the mail program on your server and set “sendmail_from” to sender’s email address.


[mail function]

sendmail_path = /usr/sbin/sendmail -t

sendmail_from = you@yourdomain


PHP mail function sample code



// The message

$message = “Line 1\nLine 2\nLine 3”;

// In case any of our lines are larger than 70 characters, we should use wordwrap()

$message = wordwrap($message, 70);

// Send

mail(‘,‘, ‘The Subject’, $message);


refer :

Easy way to select numerical data from MySQL table

I’ll explain this using a example,

Lets thing we have table called EMP and column called SALARY.
Now suppose there are numerical data and string data in the SALARY column. (ex: 12000, 25000, not available, null…)
For this kind of columns we can use following method to select only numerical data;


Simple PHP,AJAX application for get updates without doing any action at the client side using prototype JavaScript framework

This sample program contains 5 php files as follows;

1) config.php – This file use for manage the database access configuration.
2) add_name.php – This file use for send data to insert_name.php using AJAX.
3) insert_name.php – This file use for insert new record (which are receive from the add_name.php file) to the database.
4) view_names.php – This file use for view the database and database changes.
5) select_names.php – This file use for get all database data and print.

I have user a javascript framework called “PROTOTYPE” to develop this example (don’t worry, its not gona be a hard job for you). It is a single javascript file. So you have to download the latest version of it from (the file called prototype.js)

config.php is required for manage your database connection information easily.
// change the parameters to connect to your DB
// CHANGE ONLY $db_host, $db_name, $username, $password


add_name.php is provide a text field for enter the data (eg: names) into the database. By clicking the insert button the text form data send to the insert_name.php through ajax functions of prototype javascript framework.


function insertName(){
new Ajax.Request(‘insert.php’, {
parameters: $(‘name’).serialize(true),

insert_name.php is insert post data to the database.
// Connection to Database
// Remove HTML tag to prevent query injection
$name = strip_tags($_POST[‘name’]);

echo $name;
} else { echo ‘0’; }

view_names.php is print the data of the database. It call the select_names.php file and get the data.

DB names

new Ajax.PeriodicalUpdater(‘names’, ‘select_names.php’,
method: ‘get’,
insertion: Element.update,
frequency: 1,
decay: 1

selest_names.php is get the data from the database and print.
while ($row = mysql_fetch_array($result)){
echo “”.$row[0].””;
echo “”;


How to send HTTP request using PHP?

There is a predefined php class called HttpRequest. By using this class we can create object for handle HTTP requests. There are list of function to handle it. Refer PHP manual and get some idea about this class.

In WAMP before use this objects you need to make some changes in php.ini file. Add following line into the php.ini file (somewhere near in the extension).
user HttpRequest object to handle get method http request
$r= new HttpRequest(‘’, HttpRequest::METH_GET);
echo $r->getResponseBody();

Simple php sample code for privent SQL injection attacts


if(isset($_POST[“un”]) && isset($_POST[“pw”])){


$username = mysql_real_escape_string($_POST[“un”]);
$password = mysql_real_escape_string($_POST[“pw”]);

$sql = “SELECT * FROM user WHERE id = ‘$username’ AND name = ‘$password’;”;
$result = mysql_query($sql);
echo “you loged in….”;


Id :

Password :

How to execute php files without loading it

This method will execute the file_handle.php file and return the html result. So we can simply use this to database updates using this (use get method for pass inputs).
echo “Start”;
echo “end”;

Php function for search from a file

If you have the start and end points, you can get the content of that two points. (as a example if the start and end point are and then u can get the content of these tags using this function. eg: content)

$t = my_strip(“abc”,”xyz”,$contents);

echo $t;

ntbfjkb n jABCjergnv
fvb j njrbn ntbfjkb n jegnb ef
g45yyyXYZtrgjrgbXYZk oi iABCyji oni jij

jergnv fvb j njrbn ntbfjkb n jegnb ef g45yyy

%d bloggers like this: