我有以下PHP代码,用于服务移动应用程序的请求,因此它不会在浏览器中执行,然后我发现邮件功能不起作用,但是如果我在单独的php中执行邮件功能代码浏览器中的文件,可以发送邮件。所以我想问一下,即使它没有在浏览器中运行,我怎样才能让我的 PHP 文件可以发送邮件?
这是我的PHP代码:
$_Type = $_POST['Type'];
$_ClientID = $_POST['ClientID'];
$_TechID = $_POST['TechID'];
$_SiteID = $_POST['SiteID'];
function checkin($DB, $TechID, $ClientID, $SiteID){
$dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
if(!$dbConnection){
die('Error! ' . mysql_error());
}
mysql_select_db($DB['database'], $dbConnection);
$result1 = mysql_query("SELECT COUNT(*) FROM Log") or die('Error! ' . mysql_error());
$query = "SELECT `Type` FROM `Log` WHERE `TechID` = '".$TechID."' ORDER BY LogTime DESC LIMIT 1";
$result2 = mysql_query($query) or die('Error! ' . mysql_error());
while($row1 = mysql_fetch_array($result1)){
$count = $row1['COUNT(*)'];
if(mysql_num_rows($result2) > 0){
while($row2 = mysql_fetch_array($result2)){
if(trim($row2['Type'])!="Checkin"){
$count = $count+1;
$timezone = "Asia/Hong_Kong";
if(function_exists('date_default_timezone_set'))
date_default_timezone_set($timezone);
$Time = date('Y/m/d H:i');
mysql_query("INSERT INTO Log (LogID, TechID, ClientID, SiteID, LogTime, Type)
VALUES (".$count.", '".$TechID."', ".$ClientID.", ".$SiteID.", '".$Time."', 'Checkin')");
}else{
mail('me@gmail.com', 'Test mail', 'If you can read this, everything was fine!');
}
}
}else{
$count = $count+1;
$timezone = "Asia/Hong_Kong";
if(function_exists('date_default_timezone_set'))
date_default_timezone_set($timezone);
$Time = date('Y/m/d H:i');
mysql_query("INSERT INTO `Log` (`LogID`, `TechID`, `ClientID`, `SiteID`, `LogTime`, `Type`)
VALUES (".$count.", '".$TechID."', ".$ClientID.", ".$SiteID.", '".$Time."', 'Checkin')");
}
}
}
checkin($DB, $_TechID, $_ClientID, $_SiteID);
这里的情况是我的程序将检查用户之前是否已签入,如果他已签入,则会向我发送一封邮件,这就是我想要做的。