Ciao scusami, ho poca esperienza in php, ed ho un problema con facile form.Un mio vecchio collega ha sviluppato un sito ed ha inserito Facile Form per la sezione Lavora Con Noi,che però non esegue l'invio degli allegati, me li carica nella cartella Upload del componente ma quando leggo l'email non ricevo il file allegato.Di seguito ti scrivo il codice che è stato inserito,potresti darci un'occhiata e se possibile indicarmi l'errore,te ne sarei davvero grato.
Codice:
// declare globals used in this piece
global $Itemid, $my;
// load the standard piece library
$this->execPieceByName('ff_InitLib');
// get values from submission
$lettera = ff_getSubmit('lettera_input');
$area = ff_getSubmit('area_input');
$file = ff_getSubmit('file_input');
// Valorizzo le variabili relative all'allegato
$allegato = $_FILES['file_input']['tmp_name'];
$allegato_type = $_FILES['file_input']['type'];
$allegato_name = $_FILES['file_input']['name'];
// get the userid of a superadministrator. the article will be created
// by the superadmin, but use as author alias the name of the person
// who submitted it.
$creator = ff_select("select id, email, sendEmail from #__users where gid=25");
$creator = $creator[0]; // take first row
// format text, date and state
$text = ff_markdown($text);
$date = date( "Y-m-d H:i:s" );
// update #__messages table for backend notices
$headers = "From: lavora con noi";
$subject = "Candidatura " . $area;
$message = "Ricevuta candidatura per area " . $area . "\n\nLettera di presentazione.\n" . $lettera;
ff_query(
"insert into #__messages (user_id_from, user_id_to, date_time, subject,message) ".
"values ('$creator', '$creator->id', '$date', '$subject','$message')"
);
// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($allegato))
{
// Apro e leggo il file allegato
$file = fopen($allegato,'rb');
$data = fread($file, filesize($allegato));
fclose($file);
// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));
// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
// Definisco il tipo di messaggio (MIME/multi-part)
$message .= "This is a multi-part message in MIME format.\n\n";
// Metto il separatore
$message .= "--{$mime_boundary}\n";
// Questa è la parte "testuale" del messaggio
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n";
$message .= $messaggio . "\n\n";
// Metto il separatore
$message .= "--{$mime_boundary}\n";
// Aggiungo l'allegato al messaggio
$message .= "Content-Disposition: attachment;\n";
$message .= " filename=\"{$allegato_name}\"\n";
$message .= "Content-Transfer-Encoding: base64\n\n";
$message .= $data . "\n\n";
// chiudo con il separatore
$message .= "--{$mime_boundary}--\n";
}
else
{
$message = $lettera;
}
// Invio la mail
if (mail($creator->email, $subject, $message, $headers))
{
ff_redirectSelf("&ff_page=2");
}else{
ff_redirectSelf("&ff_page=3");
}
// send a mail notice to superadmin
/*
if ($creator->sendEmail) {
// if sent by unregistred we dont know the email
if ($my->id) $from = $my->email; else $from = "somebody@unknown.com";
$this->sendMail(
$from, // senders email
$name, // senders name
$creator->email, // recipient email
$subject, // subject line
$message // the message
);
} // if
*/