This is a serious problem for me. I am using some code from a script I found and like because it's complete but I am having one problem with it and it's easier to ask her because then I get an explanation of whats wrong.
The problem is it won't send the email. It fails and throws the error message of failed to send.
It used to work and now it does not, the Webhost says they did some upgrades to PHP Version 5 but I am using Version 4 with this script.
Below is the code for the forgot password, the problem is because the password is MD5 I can't it again, and if I can't send an email then I won't know what the password is. I have resorted to posting the information on fail just so the password can be retrieved, but that's insecure.
PHP Code:
function Forgot_pwd_form(){
global $error_msg;
echo "<center><font class=\"title\">"._SEND_NEW_PASSWORD."</font>
<form method='POST' action='users.php'>
<table border='0' cellpadding='4'>
<tr>
<td bgcolor='#E2E2E2'>"._USERNAME." :</td>
<td bgcolor='#E2E2E2'><input type='text' name='username' size='11'></td>
</tr>
<tr>
<td bgcolor='#E2E2E2'>"._EMAIL." :</td>
<td bgcolor='#E2E2E2'><input type='text' name='email' size='11'></td>
</tr>
<tr>
<td> </td>
<td>
<input type='hidden' name='maa' value='do_Forgot_pwd'>
<input type='submit' value='"._SEND_PASSWORD."'></p>
</td>
</tr>
</table><center>$error_msg</center>
</form>";
}
function Forgot_pwd(){
global $user, $prefix, $db;
Forgot_pwd_form();
}
function do_Forgot_pwd(){
global $user, $prefix, $db, $email, $username, $error_msg, $site_name ,$site_email, $site_url;
$result = $db->sql_query("SELECT * FROM ".$prefix."_users WHERE username='$username' AND email='$email'");
$check = $db->sql_numrows($result);
if($check == 1){
function new_pwd() {
$chars = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pwd = $pwd . $tmp;
$i++;
}
return $pwd;
}
$new_pwd = new_pwd();
$md5_password = md5($new_pwd);
$sql = $db->sql_query("UPDATE ".$prefix."_users SET password='$md5_password' WHERE email='$email'");
$eol ="\r\n";
$subject = ""._NEW_PASSWORD."";
$message = "$eol";
$message .= ""._HELLO." $username, $eol";
$message .= " $eol";
$message .= ""._YOU_ARE_RECEIVING_EMAIL." $site_name. $eol";
$message .= " $eol";
$message .= ""._HERE_ISIT_BELOW." $eol";
$message .= "--------------------------$eol";
$message .= ""._USERNAME.": $username $eol";
$message .= ""._PASSWORD.": $new_pwd $eol";
$message .= "-------------------------- $eol";
$message .= ""._YOU_MAY_LOGIN_BELOW." $eol";
$message .= "$site_url $eol";
$message .= " $eol";
$message .= ""._YOU_CAN_OFCOURSE_CHANGE_PWS." $eol";
$message .= " $eol";
$message .= "-- $eol";
$message .= "-"._THANKS." $eol";
$message .= "$site_name $eol";
$message .= " $eol";
$message .= ""._THIS_EMAIL_AUTO_GENERATED." $eol";
$message .= ""._DONT_RESPOND_WILL_IGNORED." $eol";
#set email headers to aviod spam filters
$headers .= "From: ".$site_name."<".$site_email.">".$eol;
$headers .= "Reply-To: ".$site_name."<".$site_email.">".$eol;
$headers .= "Return-Path: ".$site_name."<".$site_email.">".$eol;
$headers .= "Message-ID: <".time()."-".$site_email.">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol.$eol;
if(!mail($email,$subject,$message, $headers)){
die (""._EMAIL_DIE."");
}
//print success message and redirect browser
msg_redirect(""._NEW_PWD_SENT_TO_YOUR_EMAIL."","users.php","10");
//this else for : if($check == 1){
}else{
Forgot_pwd_form();
echo "<center><font class=\"error\">"._WRONG_USEREMAIL."</font></center><br>";
}
}
If there is a better way of doing this please advise as I would like to understand HTML email as I am working on a newsletter script that uses this same structure.
Bookmarks