Salve a tutti,
mi scuso se la richiesta potrà sembrare stupida ma ho una form scritta in HTML con risposta in PHP alla quale non riesco a fare 2 cose:
1) eliminate l'obbligatorietà dei campi su tutti (il campo telefono non vorrei fosse obbligatorio)
2) vorrei che all'utente che compila la form arrivasse una mail di ringraziamento
Questo è il codice che sto utilizzando
PAGINA HTML DELLA FORM
codice:<divclass="form_register"> <formaction="contact.php"name="contactform"class="row"method="post"> <divid="input_nome"class="col-md-12"> <inputid="name"class="form-control"type="text"name="first_name"placeholder="Nome*"> </div> <divid="input_cognome"class="col-md-12"> <inputid="cognome"class="form-control"type="text"name="cognome"placeholder="Cognome*"> </div> <divid="input_email"class="col-md-12"> <inputid="email"class="form-control"type="text"name="email"placeholder="Email*"> </div> <divid="input_phone"class="col-md-12"> <inputid="phone"class="form-control"type="text"name="phone"placeholder="Telefono"> </div> <!-- Submit Button --> <divid="form_register_btn"class="text-center"> <inputclass="btn btn-primary btn-lg"type="submit"value="Richiedi"id="submit"> </div> </form> </div>
PAGINA CONTACT.PHP
codice:<?php header('Content-Type: text/html; charset=utf-8'); if(isset($_POST['email'])){ // EDIT THE 2 LINES BELOW AS REQUIRED $email_to ="info@xxx.it"; $email_subject ="Iscrizione gratuita"; $first_name = $_POST['first_name'];// required $email_from = $_POST['email'];// required $subject = $_POST['subject'];// required $comments = $_POST['message'];// required $cognome = $_POST['cognome'];// required $phone = $_POST['phone']; $email_message ="Sotto tutti i dettagli.\n\n"; function clean_string($string){ $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .="Nome: ".clean_string($first_name)."\n"; $email_message .="Cognome: ".clean_string($cognome)."\n"; $email_message .="Email: ".clean_string($email_from)."\n"; $email_message .="Telefono: ".clean_string($phone)."\n"; // create email headers $headers ='From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/'. phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- Message sent! (change the text below as you wish)--> <divclass="container"> <divclass="row"> <divclass="col-sm-6 col-sm-offset-3"> <divid="form_response"class="text-center"> <imgclass="img-responsive"src="img/thumbs/mail_sent.png"alt="image"/> <h1>Congratulazioni!!!</h1> <p>Grazie <b><?=$first_name;?></b>, per esserti registrato</p> </div> </div> </div> </div> <!--End Message Sent--> <?php } ?>
Qualcuno mi può aiutare?
Grazie