Ciao a tutti sto sbattendo la testa da giorni per un form in cui devo allegare un cv. Ho provato in tutti i modi ma non mi riesce. Se vi posto il codice potete gentilmente darmi una mano poichè ok il PHP ma non sono competente più di tanto. In pratica è un semplice form con nome, cognome, telefono, email, ecc ma siccome nel file php ci sono gli array come faccio a fare il tutto? Vi posto il form ed il file php. Se mi aiutate ve ne sono grato. GRAZIE!!
<form id="contact-form" method="post" action="contatti.php" role="form">
<div class="row">
<div class="span4 form-group">
<label for="form_name"></label>
<input id="form_name" type="text" name="name" class="input-block-level" placeholder="Nome e cognome *" required="required" data-error="Firstname is required.">
<div class="validation"></div>
</div>
<div class="span4 form-group">
<label for="form_lastname"></label>
<input id="form_lastname" type="text" name="azienda" class="input-block-level" placeholder="Azienda *" required="required" data-error="Lastname is required.">
<div class="validation"></div>
</div>
<div class="span4 form-group">
<label for="form_email"></label>
<input id="form_email" type="email" name="email" class="input-block-level" placeholder="Email *" required="required" data-error="Valid email is required.">
<div class="validation"></div>
</div>
<div class="span4 form-group">
<label for="form_phone"></label>
<input id="form_phone" type="tel" name="phone" class="input-block-level" placeholder="Telefono *">
<div class="validation"></div>
</div>
<div class="span8 form-group">
<textarea class="input-block-level" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
<div class="text-center">
<input name="privacy" id="privacy" type="radio" value="si" /> Autorizzo trattamento
<a href="privacy.htm"> Privacy Policy </a></p>
<input type="submit" class="btn btn-theme" value="Invia Messaggio">
</div>
</div>
</div>
</form>
<?php
/*
* CONFIGURE EVERYTHING HERE
*/
// an email address that will be in the From field of the email.
$from = 'Preventivo dal sito <info@irmap.it>';
// an email address that will receive the email with the output of the form
$sendTo = 'Messaggio dal sito <info@irmap.it>';
// subject of the email
$subject = 'Messaggio dal sito';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Name', 'azienda' => 'Azienda', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message', 'privacy' => 'Privacy');
// message that will be displayed when everything is OK
$okMessage = 'Il tuo messaggio è stato inviato correttamente. Verrai contattato al più presto. Grazie!';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
/*
* LET'S DO THE SENDING
*/
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
if(!$_POST['privacy']){ //Non selezionata
echo 'Attenzione! Non hai accettato la Privacy.';
return;
}
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailText = "You have a new message from your contact form\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
// if requested by AJAX request return JSON response
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
// else just display the message
else {
echo $responseArray['message'];
}
?>