My associate and I are writing an email script that allows attatchments similar to how gmail does it. Unfortunately when we click "Submit" it loops through and doesn't actually send. If you could please take a look at the code and let me know if you see any obvious mistakes I would appreciate it. Also if you wish I will give you access to the CMS so you can try it out yourself. Professional/experienced coders only please.

-------------Step 2 is the main part.------------


PHP Code:
<?
$filename 
"emailteams.php";

include(
"includes/classes/mailer.class.php");

function 
displayteams(){


?>
<h3>Email Teams</h3>
Please select one of the teams below:<br>

<form method="post" id="emailteam" name="emailteam" action="index.php?section=emailteams.php&go=step2&id=<? echo $tid?>">

<select name="teams" onChange="location=document.emailteam.teams.options[document.emailteam.teams.selectedIndex].value;" value="go" >
<option selected name="emailteam"value="">---Select Team---</option>
<?
$teaminfo 
mysql_query("SELECT * FROM Teams");
while(
$row3 mysql_fetch_array($teaminfo)) {

$teamsid $row3['teamsID'];
$tname $row3['tName'];
$active $row3['isActive'];

$playerteams mysql_query("SELECT * FROM Teams WHERE teamsID='$teamsid'");
$row7 mysql_fetch_array($playerteams);
$tid $row7['teamsID'];

$getnumplayers mysql_query("SELECT DISTINCT playerID FROM PlayerTeams WHERE teamsID='$tid'");
$numplayers mysql_num_rows($getnumplayers);
?>

<option name="emailteam" value="index.php?section=emailteams.php&go=step2&id=<? echo $teamsid?>"><? echo "$tname";  ?></option>
</option>

<? ?>
</select>
</form>

<?
}

function 
displayplayers($var1,$var2,$var3) {


$id $_GET['id'];
$adminfname $var1;
$adminlname $var2;
$adminemail $var3;

$playerteams11 mysql_query("SELECT * FROM Teams WHERE teamsID='$id'");
$row11 mysql_fetch_array($playerteams11);
$teamname $row11['tName'];

?>
<h3>Email Teams</h3>
<?
echo "<div style='margin:4px;'><b>Team Name:</b> $teamname (ID: $id)<P>Number of players on this team $numplayers";
echo 
"<p style='margin:0px;margin-bottom:7px;'><b>Check each player you would like to email then click submit.</b></p></div>";
?>

<form method="post" target="hiddenframe" id="emailteam" name="emailteam" enctype="multipart/form-data" action="index.php?section=emailteams.php&go=step3">
<b>* Your name:<br />
<input name="name" value="<? echo "$var1 $var2"?>" size="40" maxlength="50" />
</b>
<br>
<b>* Email address:</b><br />
<input type="text" name="email" value="<? echo $adminemail?>" size="40" maxlength="50" />
<br>
<b>* Subject:</b><br />
<input type="text" name="subject" size="50" maxlength="75" />
<br />
<label for="file">Attachments:</label><br>
<!-- JavaScript is called by OnChange attribute -->
<input type="file" name="filefieldname" id="fileField" /><input type="button" OnClick="jsUpload(fileField);" value="attach">

<br />
<script type="text/javascript">
/* This function is called when user selects file in file dialog */
function jsUpload(upload_field)
{
    // this is just an example of checking file extensions
    // if you do not need extension checking, remove
    // everything down to line
    // upload_field.form.submit();

    var re_text = /\.jpg|\.gif|\.pdf|\.txt|\.xml|\.zip/i;
    var filename = upload_field.value;

    /* Checking file type */
    if (filename.search(re_text) == -1)
    {
        alert("File does not have (jpg, gif, pdf, txt, xml, zip) extension");
        upload_field.form.reset();
        return false;
    }

    upload_field.form.submit();
    /* document.getElementById('upload_status').value = "uploading file..."; */
    /* upload_field.disabled = true; */
    return true;
}
</script>
<p id="uploadedfile" >
</p>
<iframe name="hiddenframe" style="display:none" >Loading...</iframe>

<br />
<b>* Message:</b>
<br><textarea name="message" rows="8" cols="65" tabindex="40">
</textarea></p>

<center>
<table cellspacing="0" cellpadding="3" style="border: 1px solid #990000;" width="700">
<tr><td width="90" class="tabletop"><a href="javascript:checkAll(document.emailteam.check);" class="tabletop">Chk</a>|<a href="javascript:uncheckAll(document.emailteam.check);" class="tabletop">Un Chk</a></td><td width="120" class="tabletop"><a href="index.php?section=emailplayer.php&sort=pName" class="tabletop">First Name</a></td></td><td width="120" class="tabletop"><a href="index.php?section=emailplayer.php&sort=pLName" class="tabletop">Last Name:</a></td><td class="tabletop" width="370"><a href="#" class="tabletop">Primary Parent/Guardian:</a></td></tr>


<?

$playerteams 
mysql_query("SELECT * FROM PlayerTeams WHERE teamsID='$id'");
while(
$row4 mysql_fetch_array($playerteams)) {
$teamid $row4['teamsID'];
$playerid $row4['playerID'];

$playerteams2 mysql_query("SELECT * FROM Player WHERE playerID='$playerid'");
$row25 mysql_fetch_array($playerteams2);

$pid $row25['playerID'];
$pname $row25['pName'];
$plname $row25['pLName'];
$primarypg $row25['primaryPG'];
$pgname1 $row25['pgName1'];
$pgname2 $row25['pgName2'];
$pgname3 $row25['pgName3'];
$pgemail1 $row25['pgEmail1'];
$pgemail2 $row25['pgEmail2'];
$pgemail3 $row25['pgEmail3'];

if (
$primarypg == "pg1") { $pgemail $pgemail1; }
if (
$primarypg == "pg2") { $pgemail $pgemail2; }
if (
$primarypg == "pg3") { $pgemail $pgemail3; }

if (
$primarypg == "pg1") { $pgname $pgname1; }
if (
$primarypg == "pg2") { $pgname $pgname2; }
if (
$primarypg == "pg3") { $pgname $pgname3; }

if (
$pgemail2 == "") { $pgemail2 ""; } else { $pgemail2 ", $pgemail2"; }
//if ($pgemail3 == "") { $pgemail3 = ""; } else { $pgemail3 = ", $pgemail3"; }

?>

<tr><td align="center" style="border-top: 1px solid #990000;"><input type="checkbox" name="check[]" value="<? echo $pid ?>"></td><td style="border-top: 1px solid #990000;"><a href="index.php?section=viewplayer.php&id=<? echo $playerid?>"><b><? echo $pname?></b></a></td><td style="border-top: 1px solid #990000;"><a href="index.php?section=viewplayer.php&id=<? echo $playerid?>"><b><? echo $plname?></b></a></td><td style="border-top: 1px solid #990000;"><b><? echo "$pgname"?></b> - <? echo "$pgemail"?></td></tr>

<?

//end playerteams


?>

<tr><td colspan="4" style="border-top: 1px solid #990000;">

<input type="submit" name="submit" value="Submit" /></td></tr>
</table></center>
<p align="center" style="margin-top:3px;">*Click a player's first or last name to see his or her profile.</p>

</form>

<?

// end step2


}
// step 3

function emailplayers() {

$target_path "temp/";

$target_path $target_path basename$_FILES['filefieldname']['name']);


if(
move_uploaded_file($_FILES['filefieldname']['tmp_name'], $target_path)) {
    echo 
"The file ".  basename$_FILES['uploadedfile']['name']).
    
" has been uploaded";
} else{
    echo 
"There was an error uploading the file, please try again!";
}
?>

<script>
parent.document.getElementById('uploadedfile').innerHTML += '<br><a href="temp/<?php echo $_FILES['filefieldname']['name'?>"><?php echo $_FILES['filefieldname']['name'?></a>';
</script>

<?

// just userful functions
// which 'quotes' all HTML-tags and special symbols
// from user input
function safehtml($s)
{
    
$s=str_replace("&""&amp;"$s);
    
$s=str_replace("<""&lt;"$s);
    
$s=str_replace(">""&gt;"$s);
    
$s=str_replace("'""&apos;"$s);
    
$s=str_replace("\"""&quot;"$s);
    return 
$s;
}


$playerschk $_POST['check'];
echo 
"Checked Array is: $playerschk";

echo 
"<p>Your message has been sent to the following addresses:";
foreach(
$_POST['check'] as $value) {

// $check_msg .= "$value\n";
// echo "$value<br>";


$playeremails mysql_query("SELECT * FROM Player WHERE playerID='$value'");
$row2 mysql_fetch_array($playeremails);


$pname $row2['pName'];
$plname $row2['pLName'];
$primarypg $row2['primaryPG'];
$pgname1 $row2['pgName1'];
$pgname2 $row2['pgName2'];
$pgname3 $row2['pgName3'];
$pgemail1 $row2['pgEmail1'];
$pgemail2 $row2['pgEmail2'];
$pgemail3 $row2['pgEmail3'];

if (
$primarypg == "pg1") { $pgemail $pgemail1; }
if (
$primarypg == "pg2") { $pgemail $pgemail2; }
if (
$primarypg == "pg3") { $pgemail $pgemail3; }

if (
$primarypg == "pg1") { $pgname $pgname1; }
if (
$primarypg == "pg2") { $pgname $pgname2; }
if (
$primarypg == "pg3") { $pgname $pgname3; }

$nmessage $_POST['message'];
$nsubject $_POST['subject'];
$nname $_POST['name'];




//$xmailer = new XPhpMailer ( );
//$xmailer->addr = $pgemail;
//$xmailer->to = $pgname;
//$xmailer->subject = $nsubject;
//$xmailer->from_addr = $adminemail;
//$xmailer->from_name = $nname;
//$xmailer->cc = $adminemail;
////$xmailer->attachments = array ( 'docs/project.zip', 'images/misc/me.jpg' );
//$xmailer->msg = $nmessage;
////$xmailer->is_html = TRUE;
////$xmailer->cp_base = WINDOWS_1251;
//$xmailer->SendMail ( );
echo "<p style='margin:2px'>-$pgemail</p>";
}


// print_r($_POST['check']);

var_dump($_POST['check']);

// echo "<p><b>$check_msg</b></p>";



}



switch (
$go) {

    case 
"step2":
        
displayplayers($adminfname,$adminlname,$adminemail);
        break;

    case 
"step3":
        
emailplayers();
        break;

    default:
        if (
$alogged_in == 0) {
        include(
"includes/toppage.php");
        } else {
displayteams();}

}

?>