我有忘记密码表格,用户可以在其中输入有效的电子邮件地址。我向用户发送邮件没有问题,我唯一的问题是我想从数据库(用户名和密码)向用户发送他们的帐户信息,以便他们知道他们的用户名和密码。但似乎我很难在用户的收件箱上显示他们的帐户信息。我是 PHP 新手,如果你能帮助我解决这个问题,那就太好了。
这是我的代码:
编辑:
<?php
if (isset($_POST['submit'])) {
$email_from = "example@domain.com";
$datesent = date('D m/d/Y, g:i A');
$error_message = "";
$msg = "";
$subject = "Some text here";
//some validations here
$query = "Select * from user_information where EMAIL_ADDRESS = '".$_POST['email']."'";
$result = mysql_query($query) or die("ERROR: ".mysql_error());
$check = mysql_num_rows($result);
if ($check == 0) {
$row = mysql_fetch_assoc($result);
$username = $row['USERNAME'];
$password = $row['PASSWORD'];
$fname = $row['FIRST_NAME'];
}
ob_start(); //Turn on output buffering
?>
Hi <? php echo $fname; ?>!
Here is your Account information:
Username: <? php echo $username; ?>
Password: <? php echo $password; ?>
//some text here
<?php
$message = ob_get_contents();
ob_get_clean();
$email_message = "From: ".clean_string($email_from)."\n";
$email_message. = "Sent: ".clean_string($datesent)."\n";
$email_message. = "Subject: ".clean_string($subject)."\n";
$email_message. = "\n".clean_string($message)."\n";
$headers = 'From: '.$email_from."\r\n";
$headers. = 'To: '.$email."\r\n";
$headers. = 'Sent: '.$datesent."\r\n";
$email_sent = @mail($sendto, $subject, $email_message, $headers);
} ?>