我有忘記密碼錶單,用戶可以在其中輸入其有效的電子郵件地址。我向用戶發送郵件沒有問題,我唯一的問題是我想從用戶數據庫(用戶名&密碼)向用戶發送他們的帳戶信息,以便他們知道他們的用戶名和密碼。但似乎我在如何在用戶的收件箱中顯示其帳戶信息方面遇到困難。我是PHP新手,如果能幫助我解決問題,那將是非常棒的。發送帶有PHP輸出內容的郵件將不會顯示在收件箱中
這裏是我的代碼:
編輯:
<?php
if (isset($_POST['submit'])) {
$email_from = "[email protected]";
$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);
} ?>
擺脫mail()函數前面的'@',這樣你就可以看到是否有錯誤。 –
似乎沒有發現錯誤,當我擺脫@符號的郵件()。 – tek4granted
if(isset($ _ SESSION ['submit']))這是錯誤。會話變量提交將永遠不會被設置,因此它內部的代碼將永遠不會被執行。當你提交表單時,應該是$ _POST ['submit']。基本錯誤 – sonam