Jump to content

How can I send Randomly genarated password to registered users via my email?


devil420

Recommended Posts

I'm using this type of code below. how can my site may have access to my e-mail ? and how can I send e-mails containing passwords to users.?? Plz help.

//code is like this//

if($_POST['submit']=='Register')

{

// If the Register form has been submitted

 

$err = array();

 

if(strlen($_POST['username'])<4 || strlen($_POST['username'])>32)

{

$err[]='Your username must be between 3 and 32 characters!';

}

 

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['username']))

{

$err[]='Your username contains invalid characters!';

}

 

if(!checkEmail($_POST['email']))

{

$err[]='Your email is not valid!';

}

 

if(!count($err))

{

// If there are no errors

 

$pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);

// Generate a random password

 

$_POST['email'] = mysql_real_escape_string($_POST['email']);

$_POST['username'] = mysql_real_escape_string($_POST['username']);

// Escape the input data

 

 

mysql_query(" INSERT INTO tz_members(usr,pass,email,regIP,dt)

VALUES(

 

'".$_POST['username']."',

'".md5($pass)."',

'".$_POST['email']."',

'".$_SERVER['REMOTE_ADDR']."',

NOW()

 

)");

 

if(mysql_affected_rows($link)==1)

{

send_mail( 'myemail@xx.net',

$_POST['email'],

'sitename - Your New Password',

'Your password is: '.$pass);

 

$_SESSION['msg']['reg-success']='We sent you an email with your new password!';

}

else $err[]='This username is already taken!';

}

 

if(count($err))

{

$_SESSION['msg']['reg-err'] = implode('<br />',$err);

}

 

header("Location: demo.php");

exit;

}

 

 

//but while running it on local server it shows the message "failure" as I have mentioned in the index.php. Plz provite a template codeing to solve the problem//

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.