我在腳本中遇到問題,但我不確定它爲什麼會發生,可能是由於會話或HTTP標頭。我希望以這種方式登錄腳本「當用戶登錄時,應該使用用戶信息將電子郵件發送給管理員」,因此通過在以下代碼中排除電子郵件部分,只需登錄工作良好,我也可以在單獨的文件中測試電子郵件部分精細。但我不明白爲什麼電子郵件不發送和頁面顯示爲白色的空白屏幕,下面的代碼。用戶在PHP中登錄時發送電子郵件給管理員
session_start();
$errors = array();
if(isset($_POST['submit']) == "Login") {
if(empty($_POST['username'])) { $errors[] = "Please enter Username! ";}
else { $username = mysql_real_escape_string($_POST['username']); }
if(empty($_POST['password'])) { $errors[] = "Please enter Password! ";}
else { $password = mysql_real_escape_string($_POST['password']);}
if(empty($errors)) {
$sql = mysql_query("SELECT * FROM users WHERE `username` = '".$username."' AND `password` = sha1('".$password."')");
$row = mysql_fetch_assoc($sql);
if($row) {
$_SESSION['user_login'] = true;
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['full_name'] = $row['full_name'];
/*******************Send Email***************************/
//Send user information to admin
$to = "[email protected]";
$from = "[email protected]";
//Get User Information
$Full_Name = $row['full_name'];
$Browser = $_SERVER['HTTP_USER_AGENT'];
$User_IP = $_SERVER['REMOTE_ADDR'];
// If IP address exists
// Get country (and City) via api.hostip.info
if (!empty($User_IP)) {
$country=file_get_contents('http://api.hostip.info/get_html.php?ip='.$User_IP);
list ($_country) = explode ("\n", $country);
$_country = str_replace("Country: ", "", $_country);
}
$subject = $Full_Name. " logged in!";
$message = '<html><body>';
$message .= '<table rules = "all" border="0" cellpadding="10">';
$message .= "<tr><td> </td><td> </td></tr>";
$message .= "<tr style='background: #eee;'><td colspan='2'><strong>Dear Admin!</strong></td></tr>";
$message .= "<tr><td colspan='2'>A User <strong>" .$Full_Name. "</strong> logged in with following information! </td></tr>";
$message .= "<tr><td width='30%'><strong>Name ID:</strong> </td><td>" . $Full_Name . "</td></tr>";
$message .= "<tr><td><strong>IP Address:</strong> </td><td>" . $User_IP . "</td></tr>";
$message .= "<tr><td><strong>Country:</strong> </td><td>" . $_country . "</td></tr>";
$message .= "<tr><td><strong>Browser:</strong> </td><td>" . $Browser . "</td></tr>";
$message .= "<tr><td> </td><td> </td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$headers = "From: " . $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers) or die("Error!");
echo "<script>window.open('index.php','_self')</script>";
} else {
$errors[] = "Incorrect login, please try again!";
}
}#Empty Errors
}#End Submit
可能是因爲'echo'「;'? –
好的,但我認爲它應該發送電子郵件。 – Bheem