Send email upon successfull registration

Hello there…

ok I just make a simple registration page and login page using flash which is work ok …and this is my php code I’m using



<?php
// include the Database classes
require_once('../classes/database.php');

// escape quotes and apostrophes if magic_quotes_gpc off
if (!get_magic_quotes_gpc()) {
  foreach($_POST as $key=>$value) {
    $temp = addslashes($value);
    $_POST[$key] = $temp;
    }
  }

// create a Database instance and check username
$db = new Database('localhost','','','ecard');
$sql = 'SELECT username FROM users WHERE username = "'.$_POST['username'].'"';
$result = $db->query($sql);
$numrows = $result->num_rows;

// if username already in use, send back error message
if ($numrows > 0) {
  $duplicate = 'Duplicate username. Please choose another.';
  echo 'duplicate=y&message='.urlencode($duplicate);
  }
else { // insert the data into the users table
  $sql = 'INSERT INTO users (first_name,family_name,username,pwd)
          VALUES ("'.$_POST['first_name'].'","'.$_POST['family_name'].'",
          "'.$_POST['username'].'","'.$_POST['pwd'].'")';
  $result = $db->query($sql);
  if ($result) {
    $created = 'Account created for '.$_POST['username'];
    echo 'duplicate=n&message='.urlencode($created);
    }
  }
?>

so my problem is how to insert a code for send email upon the successfull registered user…I m ean when the user open up their mail it will goes liek this

**Welcome to blaablaablaa – the fast, fun and easy way to share personalized greetings. You can begin creating your own cards immediately – just sign in with the following information: Email address: email provide by user
Password: 123456

To get started, click www.blabla.com/login.html Thanks again for joining blaablaablaa!

Sincerely,

Customer Care at blaablaablaa **

Hope U guys can guide me or some walkthrough…

'tq