There is a built in mail() function that is easy to use. Look it up, try the code and post again if you still have problems.
Yes. I tried it. But got an error saying "Access denied for user 'root'@'localhost' (using password: NO)". Is there any setting for server? This is my code
[PHP]
<?php
$err=0;
if(isset($_POST['forgot'])){
$send = $_POST['forgot'];
$sql = "SELECT Email FROM user_admin WHERE Email = '".$_POST["email"]."'";
$rs_email = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($rs_email) > 0){
$send = $_POST['forgot'];
$err=0;
}
else{
$send="";
$err=1;
}
}
if ($send == "forgot"){
$letters = array("A","B","C","D","E","F","G","H","I","J","K", "L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z","0 ","1","2",
"3","4","5","6","7","8","9","0");
$pass="";
$passlength=rand (8, 12);
for($i=0;$i<$passlength;$i++){
$pass.= $letters[rand (0, 35)];
}
$notencrypted=$pass;
$pass=md5($pass);
//echo $notencrypted;
$sql = "UPDATE user_admin SET Password ='".$pass."' WHERE Email = '".$_POST["email"]."'";
$body = "";
$body = $body."<p>Your password is : ".$notencrypted."</p>";
$subject = "Password Recovery";
$toemail = trim($_POST["my@gmail.com"]);
$headers = "From: Me <my@yahoo.com>\n";
$headers = $headers."Content-Type: text/html; charset=iso-8859-1\n"; // Mime type
mail($toemail, $subject, $body, $headers);
echo '<p>Your password has been changed and sent to your email address</p><br />';
}
else{
?>
<p>Please provide your email address and your password will be emailed to you</p><br />
<?php
if($err==1)
echo '<p style="color:#992928;">The email address that you were entered is not an existing one</p>';
?>
<form name="forgotpass" id="forgotpass" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validateforgot(this);">
<input name="email" id="email" type="text" size="25" /> <br />
<input name="forgot" value="forgot" id="forgot" src="images/submit.jpg" type="image" style="margin:5px 0 0 0;" />
</form>
<?php
}
?>
[/PHP]