will this function be safe for password and email hash/crypt? EDIT: Cleary not!
$password = mysql_real_escape_string(htmlspecialchars(trim($_POST['password'])));
$hash_algo = "sha512";
$raw_output = false;
$hash = hash($hash_algo, $password, $raw_output);
$hash_20 = substr($hash, 0, 20);
$salt = substr($hash, -20); 
$crypt = crypt ( $hash_20, $salt);
$crypt_20 = substr($crypt, 0, 20);
EDIT: Here is the code I'm using now. I think this one is pretty safe. It's a PBKDF2 password hash function with a random salt generator.
So, here is the PBKDF2 function. p is for password. s is for salt. c is for iteration kl is for key lenght. a is for hash algorithm.
function pbkdf2( $p, $s, $c, $kl, $a = 'sha256' )
{ 
    $hl = strlen(hash($a, null, true)); # Hash length
    $kb = ceil($kl / $hl);              # Key blocks to compute
    $dk = '';                           # Derived key
    # Create key
    for ( $block = 1; $block <= $kb; $block ++ ) {
        # Initial hash for this block
        $ib = $b = hash_hmac($a, $s . pack('N', $block), $p, true);
        # Perform block iterations
        for ( $i = 1; $i < $c; $i ++ )
            # XOR each iterate
            $ib ^= ($b = hash_hmac($a, $b, $p, true));
        $dk .= $ib; # Append iterated block
    }
    # Return derived key of correct length
    return substr($dk, 0, $kl);
}
Salt generator:
function salt( $length )
{
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";  
    $salt="";
    $size = strlen( $chars );
    for( $i = 0; $i < $length; $i++ )
    {
        $salt.= $chars[ rand( 0, $size - 1 ) ];
    }
    return $salt;
}
In use:
if(isset($_POST['submit']))
{
    $Password = mysql_real_escape_string(htmlspecialchars(trim($_POST['Password'])));
    //To make sure the salt has never more chars than the password.
    $salt_length = strlen($Password); 
    $salt = salt($salt_length);
    //Hash Password 
    $hash = base64_encode(pbkdf2($Password, $salt, 100000, 32));
    //--------------//
}
Googling a bit find out that 100000 iterations is pretty safe but I guess 10000 will be enough tho.
 
    