og sådan her ser script ud:
<? }
function SendAutoMails($email) {
if ($email == "Ja") {
$number = 0;
$result = mysql_query("Select * from plmatchdata where mail_sendt = 'Nej' && homescore is not NULL && awayscore is not NULL;") or die (mysql_error());
while($row = mysql_fetch_array($result)) {
$result2 = mysql_query("Select * from plpredictiondata where matchid = '". $row["matchid"] ."'") or die (mysql_error());
while($row2 = mysql_fetch_array($result2)) {
$result3 = mysql_query("Select * from pluserdata where userid = '". $row2["userid"] ."'") or die (mysql_error());
$row3 = mysql_fetch_array($result3);
$text = "<html>
<head>
<title>Kampe spillet</title>
<link rel=\"stylesheet\" href=\"
http://www.tipkampen.dk/common.css\" type=\"text/css\">
</head>
<body class=\"MAIN\"><script type='text/javascript'><!--
google_ad_client = 'pub-0589142578060587';
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = '468x60_as';
google_ad_channel ='';
google_color_border = '687F99';
google_color_bg = '687F99';
google_color_link = '000000';
google_color_url = 'ffffff';
google_color_text = '000000';
//--></script>
<script type='text/javascript'
src='
http://pagead2.googlesyndication.com/pagead/show_ads.js'></script><br>
<p>Her kan du se hvad resultatet blev, og hvad du tippede på kampen:</p>";
$text .= "<table class=\"STANDTB\">\n";
$text .= "<tr>\n";
$text .= "<td class=\"TBLHEAD\" colspan=\"6\" align=\"center\"><font class=\"TBLHEAD\">$FixturesResults</font></td>\n";
$text .= "</tr>\n";
$text .= "<tr>\n";
$text .= "<td width=\"80\" align=\"center\" class=\"TBLHEAD\"><font class=\"TBLHEAD\">$Date</font></td>\n";
$text .= "<td width=\"150\" align=\"center\" class=\"TBLHEAD\"><font class=\"TBLHEAD\">$Home</font></td>\n";
$text .= "<td align=\"center\" class=\"TBLHEAD\"><font class=\"TBLROW\">G</font></td>\n";
$text .= "<td align=\"center\" class=\"TBLHEAD\"><font class=\"TBLROW\">v</font></td>\n";
$text .= "<td align=\"center\" class=\"TBLHEAD\"><font class=\"TBLROW\">G</font></td>\n";
$text .= "<td align=\"center\" class=\"TBLHEAD\"><font class=\"TBLROW\">Tip G</font></td>\n";
$text .= "<td align=\"center\" class=\"TBLHEAD\"><font class=\"TBLROW\">v</font></td>\n";
$text .= "<td align=\"center\" class=\"TBLHEAD\"><font class=\"TBLROW\">Tip G</font></td>\n";
$text .= "<td width=\"150\" align=\"center\" class=\"TBLHEAD\"><font class=\"TBLHEAD\">$Away</font></td>\n";
$text .= "</tr>\n";
// First loop. Used to get all the matches
$result4 = mysql_query("SELECT * FROM plmatchdata order by matchdate where mail_sendt = 'Nej' && homescore is not NULL && awayscore is not NULL;") or die (mysql_error());
while ($row4 = mysql_fetch_array($result4)) {
$result5 = mysql_query("Select * from plpredictiondata where matchid = '". $row4["matchid"] ."'") or die (mysql_error());
$row5 = mysql_fetch_array($result5);
$matchid = $row4["matchid"];
$hometeam = stripslashes($row4["hometeam"]);
$awayteam = stripslashes($row4["awayteam"]);
$homescore = $row4["homescore"];
if ($homescore == null) {
$homescore = " ";
}
$awayscore = $row4["awayscore"];
if ($awayscore == null) {
$awayscore = " ";
}
$date = $row4["matchdate"];
$datetext = GetDateFromDatetime($date);
$text .= "<tr>\n";
$text .= "<td class=\"TBLROW\"><font class=\"TBLROW\"><a href=\"showpredictionsformatch.php?sid=$SID&matchid=$matchid&date=$date\">$datetext</a></font></td>\n";
$text .= "<td class=\"TBLROW\"><font class=\"TBLROW\">$hometeam</font></td>\n";
$text .= "<td align=\"CENTER\" class=\"TBLROW\"><font class=\"TBLROW\">$homescore</font></td>\n";
$text .= "<td align=\"CENTER\" class=\"TBLROW\"><font class=\"TBLROW\">v</font></td>\n";
$text .= "<td align=\"CENTER\" class=\"TBLROW\"><font class=\"TBLROW\">$awayscore</font></td>\n";
$text .= "<td align=\"CENTER\" class=\"TBLROW\"><font class=\"TBLROW\">". $row5["homescore"] ."</font></td>\n";
$text .= "<td align=\"CENTER\" class=\"TBLROW\"><font class=\"TBLROW\">v</font></td>\n";
$text .= "<td align=\"CENTER\" class=\"TBLROW\"><font class=\"TBLROW\">". $row5["awayscore"] ."</font></td>\n";
$text .= "<td class=\"TBLROW\"><font class=\"TBLROW\">$awayteam</font></td>\n";
$text .= "</tr>\n";
}
$text .= "</table>\n";
$text .= "På gensyn<br><br>
www.Tipkampen.dk</body>
</html>";
// To send HTML mail, you can set the Content-type header.
//$headers = "MIME-Version: 1.0\r\n";
// additional headers
$headers = "From: Tipkampen.dk <no-reply@tipkampen.dk>\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
//$headers .= "Cc: birthdayarchive@example.com\r\n";
//$headers .= "Bcc: birthdaycheck@example.com\r\n";
@mail($row3["username"] ." <". $row3["email"] .">", "Kamp spillet",$text,$headers);
$number = $number+1;
}
mysql_query("update $dbaseMatchData set mail_sendt = 'Ja' where matchid = '". $row["matchid"] ."'") or die (mysql_error());
} ?>
<table width="100%">
<tr>
<td colspan="3" align="center" class="TBLROW">
<font class="TBLROW">
<?=$number?> mails blev sendt
</font>
</td>
</tr>
</table>
<?php
} else {
?>
<form method="POST" action="index.php?cmd=sendautomails">
<table width="100%">
<tr>
<td align="CENTER" class="TBLHEAD">
<font class="TBLHEAD">
Send email
</font>
</td>
<td align="center" class="TBLROW">
<font class="TBLROW">
<input type="radio" name="email" value="Ja">Ja
<input type="radio" name="email" value="Nej" checked="checked">Nej
</font>
</td>
<td align="center" class="TBLROW">
<font class="TBLROW">
Sender mail til alle de brugere der har tippet på en eller flere kampe, som er blevet spillet.
</font>
</td>
</tr>
<tr>
<td colspan="3" align="CENTER">
<font class="TBLROW">
<input type="SUBMIT" name="Send" value="Send mails">
</td>
</tr>
</table>
</form>
<? }
}
?>