[PHP] Semplice form

ricdil

Nuovo Utente
22 Nov 2016
5
0
1
46
Vorrei chiedere una mano per un semplice form da inserire nel mio sito. Premetto che non so quasi nulla di .php e quindi utilizzerei un codice che ho trovato su internet in diffusione gratuita che inserisco qui di seguito:

PHP:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento senza titolo</title>
</head>

<body>
<?php
 
if(isset($_POST['email'])) {
 
    
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "[email protected]";
 
    $email_subject = "Your email subject line";
 
    
 
    
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
    
 
    // validation expected data exists
 
    if(!isset($_POST['first_name']) ||
 
        !isset($_POST['last_name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['telephone']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
    
 
    $first_name = $_POST['first_name']; // required
 
    $last_name = $_POST['last_name']; // required
 
    $email_from = $_POST['email']; // required
 
    $telephone = $_POST['telephone']; // not required
 
    $comments = $_POST['comments']; // required
 
    
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$first_name)) {
 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
 
  }
 
  if(!preg_match($string_exp,$last_name)) {
 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
 
  }
 
  if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
  }
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
    
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
    
 
    $email_message .= "First Name: ".clean_string($first_name)."\n";
 
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
 
    $email_message .= "Email: ".clean_string($email_from)."\n";
 
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\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); 
 
?>
 
 
 
<!-- include your own success html here -->
 
 
 
Thank you for contacting us. We will be in touch with you very soon.
 
 
 
<?php
 
}
 
?>
</body>
</html>

e poi c'è un file html

HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento senza titolo</title>
</head>

<body>
<form name="contactform" method="post" action="send_form_email.php">
 
<table width="450px">
 
<tr>
 
 <td valign="top">
 
  <label for="first_name">First Name *</label>
 
 </td>
 
 <td valign="top">
 
  <input  type="text" name="first_name" maxlength="50" size="30">
 
 </td>
 
</tr>
 
<tr>
 
 <td valign="top"">
 
  <label for="last_name">Last Name *</label>
 
 </td>
 
 <td valign="top">
 
  <input  type="text" name="last_name" maxlength="50" size="30">
 
 </td>
 
</tr>
 
<tr>
 
 <td valign="top">
 
  <label for="email">Email Address *</label>
 
 </td>
 
 <td valign="top">
 
  <input  type="text" name="email" maxlength="80" size="30">
 
 </td>
 
</tr>
 
<tr>
 
 <td valign="top">
 
  <label for="telephone">Telephone Number</label>
 
 </td>
 
 <td valign="top">
 
  <input  type="text" name="telephone" maxlength="30" size="30">
 
 </td>
 
</tr>
 
<tr>
 
 <td valign="top">
 
  <label for="comments">Comments *</label>
 
 </td>
 
 <td valign="top">
 
  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
 
 </td>
 
</tr>
 
<tr>
 
 <td colspan="2" style="text-align:center">
 
  <input type="submit" value="Submit">   
 </td>
 
</tr>
 
</table>
 
</form>
</body>
</html>

Ho inserito questi 2 file nella cartella www del wampserver. Quando compilo i campi mi da il messaggio che l'email è stata inviata con successo ma in realtà non manda nulla. Ovviamente nel file .php ho inserito la mail corretta.

Spero qualcuno possa aiutarmi e spero non aver violato il regolamento. Se ho sbagliato qualcosa per favore fatemelo notare.
Grazie mille a tutti.
 

Max 1

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
29 Feb 2012
4.449
338
83
La prova l'hai fatta da un server in locale o da un server in rete?
 

Max 1

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
29 Feb 2012
4.449
338
83
allora è per questo che non invia la mail, devi provare online
 

ricdil

Nuovo Utente
22 Nov 2016
5
0
1
46
Ah ecco, gentilissimo. Ora vedo un qualche hosting per fare le prove. Grazie mille.
 
Discussioni simili
Autore Titolo Forum Risposte Data
A problema con un semplice form per un loggin in php PHP 2
L [PHP] cambiare gli if in un url semplice PHP 1
L [PHP] convertire gli url ad forma semplice PHP 3
G Caricare una semplice Jpg con il PHP PHP 1
Z Semplice area privata in php PHP 6
J [PHP] sviluppare una semplice calcolatrice PHP 1
booklisa [PHP] Domanda semplice (apparantemente) PHP 4
MarcoGrazia Costruire una semplice chat in PHP non è affatto semplice. PHP 3
A una guida semplice in php PHP 2
P inizio con il php ... semplice aiuto!! PHP 12
M Semplice sito php/mysql...è veramente semplice ? PHP 5
W [OFFRO] script php+sql semplice retribuito Offerte e Richieste di Lavoro e/o Collaborazione 0
W class diagram per un semplice sito Html (con pochissimo php) HTML e CSS 0
H Semplice CMS per news con PHP e XML PHP 3
R Cerco [retribuito]programmatore php mysql per sviluppo semplice progetto di ticketing Offerte e Richieste di Lavoro e/o Collaborazione 4
A [MYSQL+PHP]Non riesco a fare la query!!!Penso sia semplice.. PHP 1
M Semplice php client e web service scritto in c# non funzionanti PHP 0
F Cerco Hosting con VECCHIE versioni di php Hosting 0
Cosina Captcha php PHP 1
S passare un valore da un form a un file .php con metodo post PHP 4
N php msyql PHP 6
N php problemi a visualizzare video PHP 3
A menu a tendina php PHP 1
D protezione cartelle: blocco visualizzazione/scaricamento contenuto, ma abilitazione utilizzo dati da parte di file .php presenti sul sito Web Server 1
F Php date_diff PHP 1
K [PHP] Aggiungere caratteri ad una stringa in base alla lunghezza della stessa PHP 2
C Wp-admin a file php WordPress 5
Lino80 [Retribuito] Cerco programmatore php per modifica/inserimento funzione/valori da un plugin importer wordpress Offerte e Richieste di Lavoro e/o Collaborazione 0
csi Inviare file jpg in locale alla stampante con php PHP 0
M Passaggio variabili array php su un tasto jq PHP 3
E Php aggiornamento tabella PHP 9
G phpmailer e php 8.1 con estensione mysqli PHP 6
M Invio dati database via email php PHP 0
K [php] Problema con inner join PHP 4
K [php]form invio dati PHP 0
P Codifica caratteri speciali mysql php PHP 0
K [PHP] Problema con variabili concatenate. PHP 1
E Stampante termica escpos-php PHP 6
JeiMax Modifica codice php personalizzato PHP 2
G Come modificare un pdf in php PHP 1
U Link a doppio file PHP PHP 0
E PHP & jQuery PHP 8
N Passare array da php a javascript PHP 5
F Applicazione PHP/MySQL per prenotazioni: limitare il numero massimo di posti prenotabili PHP 20
L tipo boolean non funzionante su mariadb (mysql). E codice php 7.4. PHP 0
U PHP creare un file excel dopo ricerca nel DB PHP 0
M PHP/MySQL - Estrarre valori min e max di ogni gruppo PHP 5
F Php e fatturazione elettronica PHP 0
P lanciare script asp (o php) da jquery Javascript 1
Couting95 inserire dati da un file di testo in una tabella in php PHP 1

Discussioni simili