<?php
//***** inizio verifiche dai post
//metto un mesaggio di errore a vuoto
$ok_ko="";
$team="ManUTD 2003";
$team_mail="[email protected]";
$mail_presidente="[email protected]";
//verifica dell'email avversario (se hai messo anche l'option vuoto)
if(filter_var($_POST['Mail_Avversario'], FILTER_VALIDATE_EMAIL) == FALSE){
$ok_ko.="A T T E N Z I O N E ! ! ! C'E' UN ERRORE! Non hai inserito l'indirizzo dell'avversario! A T T E N D I. . .<br>";
}else{
$mail_avversario=$_POST['Mail_Avversario'];
}
//verifica dell'email avversario 2(se hai messo anche l'option vuoto)
if(filter_var($_POST['Mail_Avversario2'], FILTER_VALIDATE_EMAIL) == TRUE){
$mail_avversario2=$_POST['Mail_Avversario2'];
}
$oggetto="Consegna Team ManUTD 2003";
$messaggio=htmlspecialchars(trim($_POST['messaggio']));
if($_FILES['allegato']['tmp_name'] !=""){
$ammessi=array('pdf', 'eps', 'psd', 'rar', 'zip', 'csv', 'xml', 'htm', 'html', 'xlsx', 'xls', 'jpg', 'JPG', 'png', 'gif', 'doc', 'docx', 'docm', 'rtf', 'txt');//aggiungi o togli le estenzioni che ti servono
$estenzione=pathinfo($_FILES['allegato']['name'], PATHINFO_EXTENSION);
if(in_array($estenzione,$ammessi)){//è un file consentito
if (move_uploaded_file($_FILES['allegato']['tmp_name'], $_FILES['allegato']['name'])){
$allegato=$_FILES['allegato']['name'];;
//la variabile $allegato si riempie seolo se l'allegato è valido e caricato
}else{
$ok_ko.="Errore nel caricamento, riprova piu tardi! A T T E N D I. . .<br>";
}
}else{
$ok_ko.="A T T E N Z I O N E! Hai cercato di inviare un allegato di tipo non valido! A T T E N D I. . .<br>";
}
}else{
$allegato="";
}
//verifico che TUTTE le select siano state riempite
//conto solo i post chiamati [squadra]
$conteggio=0;
foreach($_POST['squadra'] as $chiave => $valore){
if(trim($valore) == ""){
$conteggio++;
break;
}
}
if($allegato=="" && $conteggio > 0 && $messaggio ==""){//RIGHE DA MODIFICARE
$ok_ko.="A T T E N Z I O N E ! ! ! C'E' UN ERRORE! Devi compilare almeno un campo tra MESSAGGIO, SQUADRA o ALLEGATO!<br> O hai lasciato vuota qualche casella giocatore! A T T E N D I. . .<br>";
}
//a questo punto (mi sembra) di aver fatto tutti i controlli
if($ok_ko != ""){//il messaggio di errore non è vuoto
//mostro il messaggio e torno alla pagina del form dopo 3 secondi
echo $ok_ko;
echo "<meta http-equiv='Refresh' content='15; URL=http://fscg.blogspot.it/p/manutd-2003.html'>";
}else{//non ci sono stati errori quindi tutto l'ambaradan di spedizione
//prepato il testo in formato html
$testo_html=nl2br($messaggio);
$testo_html.= "<table>";
if($conteggio ==0 ){//tutta la squadra è riempita
$testo_html.="<tr><td></td><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['Schema'])."</td></tr>";//Schema
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Portieri'])."</td><td>".htmlspecialchars($_POST['squadra']['Portiere'])."</td></tr>";//Portiere
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore2'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore2'])."</td></tr>";//Giocatore 2
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore3'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore3'])."</td></tr>";//Giocatore 3
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore4'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore4'])."</td></tr>";//Giocatore 4
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore5'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore5'])."</td></tr>";//Giocatore 5
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore6'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore6'])."</td></tr>";//Giocatore 6
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore7'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore7'])."</td></tr>";//Giocatore 7
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore8'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore8'])."</td></tr>";//Giocatore 8
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore9'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore9'])."</td></tr>";//Giocatore 9
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore10'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore10'])."</td></tr>";//Giocatore 10
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore11'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore11'])."</td></tr>";//Giocatore 11
$testo_html.= "<tr><td style=\"text-align:center;\"> </td><td style=\"text-align:left;\"> </td></tr>";//riga vuota la inserisci dove ti interessa
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Portieri2'])."</td><td>".htmlspecialchars($_POST['squadra']['Portiere2'])."</td></tr>";//Portiere 2
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Portieri3'])."</td><td>".htmlspecialchars($_POST['squadra']['Portiere3'])."</td></tr>";//Portiere 3
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore14'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore14'])."</td></tr>";//Giocatore 14
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore15'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore15'])."</td></tr>";//Giocatore 15
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore16'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore16'])."</td></tr>";//Giocatore 16
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore17'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore17'])."</td></tr>";//Giocatore 17
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore18'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore18'])."</td></tr>";//Giocatore 18
$testo_html.= "<tr><td style=\"text-align:center;\">".htmlspecialchars($_POST['squadra']['N_Giocatore19'])."</td><td>".htmlspecialchars($_POST['squadra']['Giocatore19'])."</td></tr>";//Giocatore 19
//eccetera sino al giocatore x
}//fine if non inseriti tutti quindi l'email viene inviato solo con il messaggio e se c'è l'allegato
$testo_html.="</table>";
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsHTML(true); // invio mail in formato HTML
$mail->SetLanguage('it','language/');
$mail->CharSet = "UTF-8";
$mail->SetFrom($team_mail,$team); //mittente
$mail->AddAddress($mail_presidente); //Mail Presidente
$mail->AddAddress($mail_avversario); //Mail Avversario
//se vuoi che arrivi una copia anche al mittente lascia AddCC, altimrnti toglilo o commentalo
$mail->AddCC($team_mail); //Invio Replay al mittente
$mail->Subject = $oggetto; //oggetto
$mail->Body = $testo_html;
if($mail_avversario2 !=""){
$mail->AddAddress($mail_avversario2); //invio email opzionale
}
if($allegato !=""){
$mail->AddAttachment($allegato); //allegato appena caricato sul server se esiste
}
if(!$mail->Send()){
echo "Errore di trasmissione, riprova più tardi!";
}else{
echo "<p>Mail o Team inviati con successo! A T T E N D I. . .</p>";
}
if(file_exists($path.$allegato)) {//verifichi che sia stato caricato
unlink($path.$allegato);// e lo elimini
}
//e torni al for, se vuoi da qualche altra parte cambia il nome del file
echo "<meta http-equiv='Refresh' content='6; URL=http://fscg.blogspot.it/p/manutd-2003.html'>";
}
?>