Thursday, December 10, 2009

How to calculate the date difference between 2 dates using php

$date1 = "2006-03-25";
$date2 = "2009-11-10";

$diff = abs(strtotime($date2) - strtotime($date1));

$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

printf("%d years, %d months, %d days\n", $years, $months, $days);

Monday, September 21, 2009

File Handling in php Through Class

class File{
private $fileName;
private $fileMode;
private $filePointer;
private $fileSize;

public function File($fileName='',$fileMode='',$fileSize=''){
//echo "
Construcor Call
";
if(!empty($fileName))
$this->fileName=$fileName;
if(!empty($fileMode))
$this->fileMode=$fileMode;
if(empty($fileSize))
$this->fileSize=filesize($this->fileName);
else
$this->fileSize=$fileSize;
}
function FileDetail(){

echo "
fileName[$this->fileName] fileMode[$this->fileMode][$this->filePointer] fileSize[$this->fileSize]
";
}
function FileExists($fileName){
if(!file_exists($fileName)){
echo "Error: This file does not exist!";
exit();
}
}
public function OpenFile(){

if(!$this->filePointer=fopen($this->fileName,$this->fileMode)){
echo "Cannot open file ($this->fileName)";
exit;
}

}
public function CloseFile(){
fclose($this->filePointer);
}
public function CheckFileMode($fileMode){
}
public function SetNameSize($fileName='',$fileSize=''){

if(!empty($fileName))
$this->fileName=$fileName;
if(empty($fileSize))
$this->fileSize=filesize($this->fileName);
else if(gettype($fileSize)=='integer')
$this->fileSize=$fileSize;
else {
echo "Erro:Invalid File Size only use Integer value!";
exit();
}

}
function SetStringSize($string){
$this->fileSize=strlen($string);

}
public function SetMode($fileMode){

$this->fileMode=$fileMode;
}


public function ReadFile($fileName='',$fileSize=''){
$this->FileExists($fileName);
$this->SetNameSize($fileName,$fileSize);

$this->SetMode('r');
$this->OpenFile();
if($this->fileSize>0)
return fread($this->filePointer,$this->fileSize);
else
return fread($this->filePointer);

}
public function WriteFile($fileName,$content,$fileSize='',$fileMode='w'){
$this->FileExists($fileName);
$this->SetNameSize($fileName,$fileSize);
if(empty($fileSize))
$this->SetStringSize($content);
$this->SetMode($fileMode);
$this->OpenFile();
if($this->fileSize>0)
return fwrite($this->filePointer,$content,$this->fileSize);
else
return fwrite($this->filePointer,$content);

}
public function SearchFile($fileName,$content){
return strpos($this->ReadFile($fileName),$content);
}
function AppendFile($fileName,$content){
$this->FileExists($fileName);
$this->SetNameSize($fileName);
$this->SetMode('a');
$this->OpenFile();
if($this->fileSize>0)
return fwrite($this->filePointer,$content,$this->fileSize);
else
return fwrite($this->filePointer,$content);
}
function ReplaceFile($fileName,$search,$replace){
return $this->WriteFile($fileName,str_replace($search, $replace,$this->ReadFile($fileName)));

}

}
?>
//Class Test
$file=new File();
echo $file->ReadFile('test.txt);
//$file->WriteFile('test.txt','this is new text in this file the quick brown fox jumpso over the lazy dog');
//echo $file->SearchFile('test.txt','love')
//$file->AppendFile('test.txt','rajput');
//$file->ReplaceFile('test.txt','rajput','change');
?>

Sunday, July 19, 2009

how can select multiple check box using javascriipt

<script type="text/javascript">

//Nanhe Kumar

var checkflag = "false";

function SelectAll(field) {



if (checkflag == "false") {



document.getElementById("selectall").value= 'Unchek All';

for (i = 0; i < field.length; i++) {

field[i].checked = true;

}

checkflag = "true";

return "Uncheck All";

} else {

document.getElementById("selectall").value= 'Sellect All';

for (i = 0; i < field.length; i++) {

field[i].checked = false;

}

checkflag = "false";

return "Select All";

}

}



</script>

<form method="post" action="" name="formuser" id="formuser" >



<input id="selectall" name="selectall" value="Select All" onclick="SelectAll(document.formuser['uid[]']);" type="checkbox"> Sellect All <br>

<input name="uid[]" value="1" type="checkbox"> One<br>

<input name="uid[]" value="2" type="checkbox"> two<br />

<input name="uid[]" value="3" type="checkbox"> three<br />

<input name="uid[]" value="4" type="checkbox"> four<br />

<input name="uid[]" value="5" type="checkbox"> five<br />

<input name="uid[]" value="6" type="checkbox"> six<br />

<input name="uid[]" value="7" type="checkbox"> seven



</form>

how can on curl mcrypt

hi
Go to php.ini file
problem 1 PHP Extension “curl” must be loaded
and find
;extension=php_curl.dll
and remove semicolon

problem 2 PHP Extension “mcrypt” must be loaded
and fined
;extension=php_mcrypt.dll

remove semicolon and restart your server

thanks

Thursday, June 11, 2009

How can store session in data base

Step1: Create A Table:
CREATE TABLE `sessions` (
`session_key` char(32) NOT NULL,
`session_expire` int(11) unsigned NOT NULL,
`session_value` text NOT NULL,
PRIMARY KEY (`session_key`)
)

Step2 : Create A connection file
configure.php
$HOST = "localhost";
$DBNAME="sessions";
$USER = "nanhe";
$PASS = "chapra";
$HANDLER = "";
$LIFETIME = get_cfg_var("session.gc_maxlifetime");
?>

Step3 : Create handler
handler.php
include("configure.php");
function sessionOpen($save_path, $session_name){

global $HOST, $DBNAME, $USER, $PASS, $HANDLER;

if (!$HANDLER = mysql_pconnect($HOST, $USER, $PASS)) {
echo("
  • Can't connect to $HOST as $USER");
    echo("
  • MySQL Error: ". mysql_error());
    die;
    }

    if (! mysql_select_db($DBNAME, $HANDLER)) {
    echo("
  • We were unable to select database $DBNAME");
    die;
    }

    return true;
    }

    function sessionClose()
    {

    return true;
    }

    function sessionRead($session_key)
    {
    global $session;
    $session_key = addslashes($session_key);

    $session_session_value =
    mysql_query("SELECT session_value
    FROM sessions WHERE session_key = '$session_key'")
    or die(mysql_error());

    if (mysql_numrows($session_session_value) == 1) {
    return mysql_result($session_session_value, 0);
    } else {
    return false;
    }
    }

    function sessionWrite($session_key, $val)
    {
    global $session;
    echo "The value=".$val;
    $session_key = addslashes($session_key);
    $val = addslashes($val);
    $session = mysql_result(mysql_query("SELECT COUNT(*) FROM sessions
    WHERE session_key = '$session_key'"), 0);

    if ($session == 0) {
    $return =
    mysql_query("INSERT INTO sessions
    (session_key, session_expire, session_value)
    VALUES ('$session_key',
    UNIX_TIMESTAMP(NOW()), '$val')")
    or die(mysql_error());
    } else {
    $return = mysql_query("UPDATE sessions
    SET session_value = '$val',
    session_expire = UNIX_TIMESTAMP(NOW())
    WHERE session_key = '$session_key'")
    or die(mysql_error());

    if (mysql_affected_rows() < 0) {
    echo("We were unable to update session
    session_value for session $session_key");
    }
    }
    return $return;
    }


    function sessionDestroy($session_key)
    {
    global $session;
    $session_key = addslashes($session_key);

    $return = mysql_query("DELETE FROM sessions
    WHERE session_key = '$session_key'")
    or die(mysql_error());
    return $return;
    }

    function sessionGc($maxlifetime)
    {
    global $session;
    $expirationTime = time() - $maxlifetime;

    $return = mysql_query("DELETE FROM sessions WHERE session_expire <
    $expirationTime") or die("sessionGc Function".mysql_error());
    return $return;
    }

    session_set_save_handler("sessionOpen", "sessionClose", "sessionRead", "sessionWrite", "sessionDestroy", "sessionGc");


    ?>
    Step4 : Test your program
  • Thursday, May 28, 2009

    Monday, May 4, 2009

    create a blank page in phpbb

    /*
    * phpBB3 blank example page.
    */

    define('IN_PHPBB', true);
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup('common');
    // include page language file
    $user->add_lang('page');
    page_header($user->lang['PAGE_TITLE']);

    /*
    Put your own code here
    */

    $template->set_filenames(array(
    'body' =>'nanhe_kumar.html'
    ));
    // parse page:
    page_footer();
    ?>

    how can your link session with two sites

    if you want login in
    www.gradtrain.com
    and my session is also available in
    gradtrain.com/forum
    ?php
    define('IN_PHPBB', true);
    define('ROOT_PATH', "forum/");

    if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {
    exit();
    }

    $phpEx = "php";
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/';
    include($phpbb_root_path . 'common.' . $phpEx);

    $user->session_begin();
    $auth->acl($user->data);
    ?>
    $auth->login('nanhe', 'nanhe', $remember, 1, 0)
    ?>
    $user->session_kill();
    $user->session_begin();
    ?>

    how can login in phpbb, forum with own created page

    Suppose your site is
    www.gradtrain.com
    and your forum is www.gradtrain.com/forum
    and if want login with your crated page
    www.gradtrain.com/forum-login.php
    then take this step
    define('IN_PHPBB', true);
    define('PHPBB_ROOT_PATH', './forum/');

    $phpbb_root_path = 'forum/';

    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    ?>
    /* Start Logout*/
    if ($user->data['is_registered']){

    echo("
    data['session_id']."'>");
    echo("");
    echo("");
    echo("
    ");
    }
    /*End Logout*/

    /*Start Login Box*/
    if (!$user->data['is_registered']){
    echo("
    ");
    echo(" Username:");
    echo("
    ");
    echo(" ");
    echo("

    ");
    echo(" Password:");
    echo("
    ");
    echo(" ");
    echo("

    ");
    echo("");
    echo("");
    //echo("");
    echo("
    ");
    }
    /*End Login Box*/

    ?>

    Friday, May 1, 2009

    The command prompt has been disabled by your administrator

    When you attempt to run CMD.exe or a batch file, you may receive the message "The command prompt has been disabled by your administrator". This is caused by restrictions placed in Registry. DisableCMD value is set to 1 or via Group Policy. To enable Task Manager, try any of these methods:

    Method 1: Using the console registry tool

    • Click Start, Run and type this command exactly as given below: (better - Copy and paste)

    Method 2: Edit the registry directly

    • Open Registry Editor (Regedit.exe) and navigate to:

    [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System]

    • In the right-pane, double-click DisableCMD and set it's data to 0

    Method 3: Using Group Policy Editor in Windows XP Professional.

    • Click Start, Run, type gpedit.msc and click OK.

    • Navigate to User Configuration \ Administrative Templates \ System

    • Double-click the Prevent access to the command prompt

    You can then disable or set the policy to Not Configured. Disabling or setting this policy to Not Configured should solve the problem.

    Related articles

    "Registry Editing has been disabled by your administrator"
    "Task Manager has been disabled by your administrator"

    Monday, April 27, 2009

    Hide .php extension with url rewriting using .htaccess

    Last time I’ve written an article about hiding php file extension where I’ve showed you how you can use .html or .asp extension of file instead of .php extension. But there was one flaw in that technique you have had to change the file extension explicitly but in this post I’m going to show you how to rewrite the URL instead of renaming the file extension Using this technique you will see product.html in the address bar of the browser but the actual file name remains product.php and you don’t need to rename the file extension. Furthermore you can rewrite the URL like product.php?id=5 to product-5.html.

    what is the benefits of rewriting URL?

    When a search engine visits the dynamic url like product.php?id=5 it does not give much importance to that URL as search engine sees “?” sign treat it as a url which keeps on changing. so we’re converting the dynamic URL like the product.php?id=5 to static url format like product-5.html. We’ll rewrite the url in such a way that in browser’s address bar it will display as a product-5.html but it actually calls the file product.php?id=5. So that why these kind of URL also named as SEO friendly URL.

    what is required for URL rewriting ??

    To rewrite the URL you must have the mod_rewrite module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter 500 Internal Sever Error. If you don’t know much about mod_rewrite module then please check this post to know how to check and enable mod_rewrite module in apache?

    Examples of url rewriting for seo friendly URL

    For rewriting the URL, you should create a .htaccess file in the root folder of your web directory. And have to put the following codes as your requirement.

    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*)\.htm$ $1.php [nc]

    The following example will rewrite the test.php to test.html i.e when a URL like http://localhost/test.htm is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.

    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1

    The following example will rewrite the product.php?id=5 to porduct-5.html i.e when a URL like http://localhost/product-5.html calls product.php?id=5 automatically.

    How to check and enable mod_rewrite module in apache

    Well there are lots of technique to check this but I’ll show you a very simple technique to check weather mod_rewrite module is enabled or not in you web server.

    1) Type in a php file and save it and run that file in the server.
    2) And now you can the list of information, just search the word “mod_rewrite” from the browser’s search menu
    3) If it is found under the “Loaded Modules” section then this module is already loaded as you see in the picture below, otherwise you need to go to the next step for enabling mod_rewrite module.

    check mod rewrite module

    How to enable mod_rewrite module in apache in xampp, wamp?

    Now, I’ll show you how to enable how to mod_rewrite module in apache installed under windows environment.
    1) Find the “httpd.conf” file under the “conf” folder inside the Apache’s installation folder.
    2) Find the following line “#LoadModule rewrite_module modules/mod_rewrite.so” in the “httpd.conf” file.You can do this easily by searching the keyword “mod_rewrite” from find menu.
    3) Remove the “#” at the starting of the line, “#” represents that line is commented.
    4) Now restart the apache server.
    5) You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”.

    How to check and enable mod_rewrite module in apache

    Well there are lots of technique to check this but I’ll show you a very simple technique to check weather mod_rewrite module is enabled or not in you web server.

    1) Type in a php file and save it and run that file in the server.
    2) And now you can the list of information, just search the word “mod_rewrite” from the browser’s search menu
    3) If it is found under the “Loaded Modules” section then this module is already loaded as you see in the picture below, otherwise you need to go to the next step for enabling mod_rewrite module.

    check mod rewrite module

    How to enable mod_rewrite module in apache in xampp, wamp?

    Now, I’ll show you how to enable how to mod_rewrite module in apache installed under windows environment.
    1) Find the “httpd.conf” file under the “conf” folder inside the Apache’s installation folder.
    2) Find the following line “#LoadModule rewrite_module modules/mod_rewrite.so” in the “httpd.conf” file.You can do this easily by searching the keyword “mod_rewrite” from find menu.
    3) Remove the “#” at the starting of the line, “#” represents that line is commented.
    4) Now restart the apache server.
    5) You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”.

    Tuesday, April 7, 2009

    ILIAS warning

    if your pear is working, you also setup php.ini file
    if you find error like this
    Warning: file(/lang/setup_lang_sel_multi.lang) [function.file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 108

    Warning: file(/lang/setup_en.lang) [function.file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 124

    Warning: parse_ini_file(/setup/ilias.master.ini.php) [function.parse-ini-file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilSetup.php on line 144

    Warning: parse_ini_file(/setup/client.master.ini.php) [function.parse-ini-file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilClient.php on line 73

    Warning: dir(/lang) [function.dir]: failed to open dir: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 192

    Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 194

    Fatal error: Call to a member function read() on a non-object in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 197

    Answer or this problem
    // ADDED BY CDRIGA
    define ("ILIAS_ABSOLUTE_PATH","/home/myusername/public_html/iliasfolder");

    Wednesday, April 1, 2009

    Installing PEAR on Godaddy shared accounts

    I recently found out how to install PEAR on a Godaddy shared hosting account.
    Visit http://pear.php.net/go-pear. Save the text displayed onto your desktop and name it go-pear.php. Upload this to your server. If you’re hosting multiple domains on the account, it’s best that you should upload this file in your root folder. Run this file on your browser and follow the on-screen instructions.
    After completing the installation, it is time to edit your php.ini file. If you are running PHP4, there should be a file in the root directory called php.ini. If you are running PHP5, there should be a file in the root directory called php5.ini. If not, create one and add the following: include_path = “.:/usr/local/php5/lib/php:/home/content/s/a/m/sample/html/PEAR”. Keep in mind that /s/a/m/sample is just an example. Doing this will ensure that every page, you create, will look in the PEAR directory so that you it will use the installed packages.
    This installation will include Pear_Frontend_Web which is the web-based admin interface. It may have created an index.php file in the directory where PEAR is installed (root). If not you can get a copy from PEAR/docs/PEAR_Frontend_Web/docs/index.php.txt. I would suggest creating a folder called pear_admin in the root directory and storing this file there. If you didn’t install PEAR in the root directory, you may need to edit this file accordingly.
    You will need to create a .htaccess and .htpasswd file in the same directory as the index.php file. An example of how the .htaccess file should look as follows:AuthUserFile /home/content/s/a/m/sample/html/pear_admin/.htpasswdAuthType BasicAuthName “Web-based PEAR Frontend”Require valid-user
    An example of how the .htpasswd file should look as follows:
    admin:cGyUX9QugYMgE
    This will create “admin” as the user name and “password” as the password. You can generate your own by going to this link - http://www.htaccesstools.com/htpasswd-generator/
    Be aware that files beginning with a dot are invisible. You may have to edit your settings on the FTP app you’re using so that you can see them.
    Once the files are created and saved, you can now go to http://your-domain.com/pear_admin/index.php. It will ask for the user name and password. Once you are logged in, you can now manage Pear via web browser. That’s it! Now you can run PEAR on a shared account from Godaddy. One less complaint
    orignal link :http://abbyandwin.net/blog/2008/06/16/installing-pear-on-godaddy-shared-accounts/

    Installing PEAR packages on WAMP

    Well, after getting caught out recently with PEAR on a client installation, I thought it a good move to write a short tutorial for anyone who needs to install PEAR packages on their WAMP installation.
    To start with, for the purposes of this blog, PEAR is a framework for implementing code libraries in PHP. In other words, it prevents you from having to re-invent the wheel - always a nice thing!
    The WAMP installation installs PHP, and at the same time installs the basic PEAR framework. There is a directory called PEAR inside whatever folder contains PHP - on my particular installation the structure is php5.2.5\PEAR. Taking a peek inside the PEAR folder will reveal it populated with the basic framework for PEAR. Most of this you can ignore - I’m not going to detail installing this here - that seems to be well covered. I just couldn’t find out how to actually enabvle the damn packages when I started, so I hope this is useful!
    Checking Configuration
    This is THE place where things can go PEAR-shaped, if you’ll allow the pun. The PEAR folder must be included in the includes path within PHP.INI. Open PHP.INI and find the line that starts with :
    include_path =
    or, if commented out
    ; include_path =
    You need to add the path to your PEAR folder to the end of this string. For example:
    include_path = “.;e:\wamp\bin\php\php5.2.5\includes;e:\wamp\bin\php\php5.2.5\PEAR”
    Now - it is CRUCIAL that there are NO spaces after or before the semi-colons that separate paths in this string. If there are, quite simply, PEAR will not work. Simple as that - any incldue path after such a space will NOT be searched by PHP.
    Once you have modified the PHP.INI file, save it and restart your WAMP installation.
    Installing a package
    First of all, identify the package(s) that you want to install. To do this, take a look at http://pear.php.net/packages.php, which lists the available packages for PEAR. Identify the ones you’re interested in - for the same of example, let’s deal with a Mailer package.
    Click on the relevant section of the Package list, and you’ll see a list of available Mail packages. Select the one of interest - choose the package ‘Mail’ and click on it. This will then display a page of details about the Mail package - and also the links to download, documentation, etc. Now, there are two ways to download stuff, depending upon whether you have access to the command line program for PEAR or not. This blog entry will assume you have - I’ll post the alternative instructions elsewhere.
    To start with, make a note of the package name - ‘Mail’.
    Check the Dependencies
    Click on the ‘Download’ tab - you will see an entry someway down the page for ‘Dependencies’. These are PEAR packages that you need to install for your chosen package to work. Make a note of the dependencies - in this case, Net_SMTP. Now click on that dependency, and check it’s dependencies - do this and you will see Net_Socket and Auth_SASL listed. The latter is optional, so I won’t bother with that. There are two other packages listed - however they’re part of the PEAR framework.
    So, we now have a list of packages to download and install. These are:
    Mail, Net_SMTP, Net_Socket. (We’ll ignore the Auth_SASL one for this example).
    Whilst you can automate the acquisition of dependencies, it’s educational to do it ‘the hard way’ at first. :) So that’s what we will do!
    Start a Command Window
    From your Windows Start menu, select the ‘Run’ entry, and enter ‘cmd.exe’. Now change directory to the PHP directory. On my machine this is:
    E:\wamp\bin\php\php5.2.5
    Once in there, type in pear list. This will list the currently installed pear packages. If it’s a new PEAR installation, there will be 3 packages listed 4 packages listed - PEAR, Archie_Tar, Console_Getopt and Structures_graph.
    Now, type in pear update-channels. this connects to the PEAR repository - where the PEAR files live - and updates your local installation with data needed to get packages.
    Now, type in:
    pear download Mail
    pear install Mail
    The former command gets a ZIP file containing the Mail package from the PEAR repository, and the latter will install the mail package. Note the messages displayed on installation - the software warns you that you haven’t got the dependencies, and gives you a suggestion of a method of downloading the dependencies - which we’ll now use to get Net_SMTP an it’s dependencies.
    We’ll also do this installation slightly different to the first one - thus showing there is more than one way to install a package. Type in:
    pear install -a Net_SMTP
    No download this time - this will go off and get Net_SMTP, and all of it’s dependencies, and install them - all in one fell swoop! The -a switch tells PEAR to get all the dependencies.
    The files will be installed in to the PEAR folder. Sometiems a PHP file will be placed in the folder itself - as happens with the DB package. Other times a new folder will be created - like for Mail - and the PHP files placed in the new folder.
    Testing the mailer.
    Here is a piece of sample code to put in to a PHP file:require_once “Mail.php”;
    $from = “Sender ”;
    $to = “Recipient ”;
    $subject = “Hi!”;
    $body = “Hi,\n\nThis is a test!”;
    $host = “mail.example.com”;
    $username = “smtp_username”;
    $password = “smtp_password”;
    $headers = array (’From’ => $from,
    ’To’ => $to,
    ’Subject’ => $subject);
    $smtp = Mail::factory(’smtp’,
    array (’host’ => $host,
    ’auth’ => true,
    ’username’ => $username,
    ’password’ => $password));
    $mail = $smtp->send($to, $headers, $body);
    if (PEAR::isError($mail)) {
    echo(”

    ” . $mail->getMessage() . “

    ”);
    } else {
    echo(”

    Message successfully sent!

    ”);
    }
    ?>
    Set up your own parameters for the mail server and the authentication required - username and password, and the address of the recipient - and if you have successfully installed PEAR Mail then you should get a mail sent. If you get any messages back refering to ‘No such file or directory’ then the chances are that the configuration of PHP.INI is a little screwed up. And there you have it!
    orignal article : http://www.joep.communityhost.org.uk/?p=30