Send a mail by php with php is not executing in browser
<p>I have the following PHP code, which is used to serve the request of a mobile app, so it will not execute in a browser, then I discover the mail function does not work, but if I execute the mail function code in a seperate php file in a browser, the mail can be sent. So I would like to ask how can I make my PHP file possible to send a mail even it is not running in a browser?</p>

<p>Here is my PHP code:</p>

<pre><code>$_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) &gt; 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);
</code></pre>

<p>The situation here is my program will check if user has checked in before, if he has checked in, a mail will send to me, this is what i want to do.</p>
