php mail function..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

php mail function..

Post by pavanpuligandla »

hii everyone,

i developed a small database driven website, in that when a new user gets registered, an email will be sent to tht user with his/her login information details,
i'm now displaying the username and password(password as a clear text) in the mail.
my client asked me not to display the password as a clear text instead they should be replaced by astricks.
its not a problem at all, i'm using smarty templates text files for email.
can anyone help me out.

example is: if user registered password is "PHPMYSQL" i need to display this as "P******L"
thanks,
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Re: php mail function..

Post by Drachlen »

Hi there.

I'm not sure if this is an ideal way of doing it, but it's a working solution.

Here's the code:

Code: Select all

$password = "PHPMYSQL";
$newpassword = $password{0}.str_repeat("*", strlen(substr($password, 1, -1))).$password{strlen($password)-1};
echo $newpassword;
Here's the breakdown for it:

$newpassword is made up of 3 parts:

1. The starting character of the password, so $password{0} refers to the first character in the string

2. A couple of functions are used together here: first, substr is used to chop off the starting and ending characters of the string. Second, strlen is used to count the total characters in the string. And finally, str_repeat is used to repeat an asterisk that many times--so this will work with any length password.

3. And the ending character is appended using $password{strlen($password)-1}

A couple of notes: A password that is 2 characters long, for example the password "HI" will always be "HI", Other than that, you also might consider simply using a fixed amount of asterisks, which would be as simple as replacing number 2 with "******"


Good luck, I hope this helps.
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: php mail function..

Post by pavanpuligandla »

hii,
thanks for your help,
but it didnot work.
here's my registration functions code.

Code: Select all

// *****************************************************************************
// Purpose  send notification message to email
// Inputs   
//              $login              - login
//              $cust_password      - password
//              $newpassword        - newpassword (Password sent to user's email with *'s)
//              $Email              - email
//              $first_name         - customer first name
//              $last_name          - customer last name
//              $subscribed4news    - if 1 customer is subscribed to news
//              $additional_field_values - additional field values is array of item
//                                  "additional_field" is value of this field
//                                  key is reg_field_ID
//              $updateOperation    - 1 if customer info is updated, 0 
//                              otherwise
// Remarks  
// Returns  
$cust_password = cryptPasswordCrypt( $cust_password, null );
$newpassword = $cust_password{0}.str_repeat("*", strlen(substr($cust_password, 1, -1))).$cust_password{strlen($cust_password)-1};
function regEmailNotification($smarty_mail, $login, $newpassword, $Email, $first_name, 
        $last_name, $subscribed4news, $additional_field_values, 
        $countryID, $zoneID, $state, $zip, $city, $address, $updateOperation )
{
    $user = array();
    $smarty_mail->assign( "login", $login );
    $smarty_mail->assign( "newpassword", $newpassword );
    $smarty_mail->assign( "first_name", $first_name );
    $smarty_mail->assign( "last_name", $last_name );
    $smarty_mail->assign( "Email", $Email );
    $additional_field_values = GetRegFieldsValues( $login );
    $smarty_mail->assign( "additional_field_values", $additional_field_values );
 
    $addresses = regGetAllAddressesByLogin( $login );
    for( $i=0; $i<count($addresses); $i++ )
        $addresses[$i]["addressStr"] = regGetAddressStr( $addresses[$i]["addressID"] , true);
    $smarty_mail->assign( "addresses", $addresses );
    
    if(CONF_ENABLE_REGCONFIRMATION){
        
        $sql = '
            SELECT ActivationCode FROM '.CUSTOMERS_TABLE.'
            WHERE Login="'.xEscapeSQLstring($login).'" AND cust_password="'.xEscapeSQLstring(cryptPasswordCrypt($cust_password, null)).'"
        ';
        @list($ActivationCode) = db_fetch_row(db_query($sql));
        
        $smarty_mail->assign('ActURL', CONF_FULL_SHOP_URL.(substr(CONF_FULL_SHOP_URL, strlen(CONF_FULL_SHOP_URL)-1,1)=='/'?'':'/').'index.php?act_customer=1&act_code='.$ActivationCode);
        $smarty_mail->assign('ActCode', $ActivationCode);
    }
    
    $html = $smarty_mail->fetch( "register_successful.txt" );
    ss_mail($Email,
        EMAIL_REGISTRATION,
        $html,
        "From: \"".CONF_SHOP_NAME."\"<".CONF_GENERAL_EMAIL.">\n".
            stripslashes(EMAIL_MESSAGE_PARAMETERS)."\nReturn-path: <".CONF_GENERAL_EMAIL.">");
 
}
 
nothing happened when i changed this code. please let me know the solution.
many thanks again for making your time.
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: php mail function..

Post by pavanpuligandla »

hii,
i'vent declared my varibales properly. its working now..
many thanks for ur help..
By the way in our registration form, password should contain minimum of 8 characters, so no need to worry about 2 charactered string.
thanks again..
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: php mail function..

Post by php_east »

why the long road ?
<input type=password ......................
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: php mail function..

Post by pavanpuligandla »

why the long road ?
<input type=password ......................
hii..
i'm using .txt files as email templates which were compiled by smarty engine..
so should need to go in this long way only..
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: php mail function..

Post by php_east »

ah ok, i thought they were html you were trying to produce. since it is text, you would have to manufacture the asteriks i guess.
Post Reply