<?php
// se hanno premuto il pulsante submit
if (isset($_POST['submit']) && $_POST['submit'] == "submit") {
// inizializzo campi obbligatori
$obbligatorio = array();
// eliminiamo il post submit
unset($_POST['submit']);
// array check obbligatorie
$array_check = array("nome", "azienda", "città", "provincia", "telefono", "email", "settore", "pubblicità", "oggetto", "messaggio", "privacy", "termini");
// inizializzo conteggio check
$ck = 0;
// ciclo array ceck obbligatorie
foreach ($array_check as $value) {
// se settata
if (isset($_POST[$value])) {
// incremento
$ck++;
}
}
// se non ne trovo neanche una
if ($ck < 5) {
$obbligatorio[] = "Checkbox obbligatorie";
}
// se sceglie no
if ($_POST['selfCandidature'] == 'no') {
// lo cancelliamo per non verificarlo
unset($_POST['expertise']);
}
// ciclo del POST
foreach ($_POST as $key => $value) {
// se non è vuoto
if (!empty($value)) {
// minimo controllo
${$_POST[$key]} = htmlentities($value);
} else {
$obbligatorio[] = "\n Il campo $key e' obbligatorio";
}
}
}
if (count($obbligatorio) == 0) {
$header = "";
$msg = "";
$boundary = '--' . md5(uniqid(time()));
$ctencoding = "8bit";
$oggetto = "Submission of a new Article";
$testo_del_messaggio.="Name: $nome\n";
$testo_del_messaggio.="Surname: $azienda\n";
$testo_del_messaggio.="Email: $città\n";
$testo_del_messaggio.="Telephone: $provincia\n";
$testo_del_messaggio.="Fax: $telefono\n";
$testo_del_messaggio.="Title of the Article: $email\n";
$testo_del_messaggio.="Category: $settore\n";
$testo_del_messaggio.="Originality of the article: $pubblicità\n";
$testo_del_messaggio.="Ethical Code: $oggetto\n";
$testo_del_messaggio.="Rules of the copyright: $messaggio\n";
$testo_del_messaggio.="Rules of the page charge: $privacy\n";
$testo_del_messaggio.="Anonymous peer review: $termini\n";
$to = "mail@.com";
$from = $_POST['email'];
$fromname = $_POST['azienda'];
$ctype = "application/octet-stream";
$header.="From: \"$fromname\" <$from>\nReturn-Path: $from\nX-Priority: 3\nTo: $to\n";
$header.="Mime-Version: 1.0\nContent-Type: multipart/mixed; \n boundary=\"$boundary\"\n";
$header.="Content-Transfer-Encoding: 8bit\n";
$msg .="This is a multi-part message in MIME format.\n--$boundary\n";
$msg .= "Content-Type: text/plain; charset=iso-8859-1\n";
$msg .= "Content-Transfer-Encoding: 8bit\n\n" . $testo_del_messaggio . "\n";
$msg .="--$boundary\nContent-type: $ctype;\n name=\"$nome\"\n";
$msg .="Content-Transfer-Encoding: base64\nContent-Disposition: attachment\n filename=\"$name\"\n";
$msg .= chr(13) . chr(10) . $content;
$result = @mail($to, $subject, $msg . "\n", $header);
if ($result) {
echo "<p>Your data and your article have been successfully sent</p> <p>Thank you very much for your contribution!</p>";
} else {
echo " <p>Error.<br>Impossible to send the data.</p><p>Try once again.</p>";
}
} else {
foreach ($obbligatorio as $value) {
echo $value . "<br/>";
echo "Torna al form";
}
}
} else {
echo "Post non settato, pagina non accessibile";
}
?>