我是一个新的php.I让一些忘记密码代码这个代码从user.checking它在数据库中检查它如果存在于数据库然后它发送密码到电子邮件。但这是一个问题,我获取first_name从数据库显示在电子邮件标题中,但提取脚本未在电子邮件中显示任何结果。 这是我的代码
<?php
error_reporting(0);
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
function getRandomPassword($length=12, $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789"){
return substr(str_shuffle($chars),0,$length);
}
$town= $_POST['email'];
if (isset($_POST['update'])) {
$length = (int)$_POST['length'];
if ($length < 6) $length = 6;
$randomPassword = getRandomPassword($length);
$sender = '';
$to = $town;
$subject = 'Password Recovery';
$from = 'johan.a.selin@gmail.com';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$sender ."\r\n".
'Reply-To: '.$user_email."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body style=height:700px;>';
$message = str_replace("{first_name}", $row['fname'], $message);
$message .= '<img src="http://cashbackshopping.se/img/logoj.jpg" alt="cashbackshopping" height="50" width="150">';
$message .= '<h1 style="color:white;width: 400px;height: 50px;text-align: center;margin-top: -3px;line-height: 2em;background: orange;">Hello!</h1>';
$message .= '<p style="color:#1FA67A;font-size:18px;">Your requested a New Password </p>';
$message .= '<p style="font-size:20px;color:red;">Your password is : <strong style="color:#38A1E3; font-size: 30px;">' . $randomPassword . '</strong></p>';
$message .= '<p style="font-size:20px;color:red;">Your First name is : <strong style="color:#38A1E3; font-size: 30px;">' . $ename . '</strong></p>';
$message .= $pass;
$message .= '<br><button style="background: orange; margin-left: 120px; margin-top: 30px;
padding: 10px;"><a href="www.cashbackshopping.se/login.php" style=" background: orange;
text-decoration: none;
font-size: 24px;color:#000;">Login here</a></button>';
$message .= '<div style="width:400px;height:50px;background:#1fa67a;margin-top:30px;"><p style="text-align: center;line-height: 4em; color: white;">© 2014-2015 Cashbackshopping.se</p></div></body></html>';
mail($to, $subject, $message, $headers);
}
$str = $randomPassword;
$skspass= md5(sha1($str));
if (isset($_POST['email']) && !empty($_POST['email'])) {
$sql = "UPDATE table
SET `password`='$skspass'
WHERE `email`='$town'";
mysql_select_db('');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
mysql_close($conn);
}
//query
$query = mysql_query("select fname from cashbackengine_users WHERE email='$town'");
//write the results
while ($row = mysql_fetch_array($query)) {
echo $row['name_first'];
$ename = $row['name_first'];
// close the loop
}
?>