Ciao a tutti,
ho creato una semplice pagina di test HTML con invio messaggio in form:
codice:<html> <body> <form action="./inviamail.php" method="POST"> <table border="0"> <tr> <td>Nome</td> <td><input type="text" name="Nome" size="30"></td> </tr> <tr> <td>Età</td> <td><input type="text" name="Anni" size="5"></td> </tr> <tr> <td>Città</td> <td><input type="text" name="City" size="30"></td> </tr> <tr> <td>Indirizzo</td> <td><input type="text" name="Address" size="30"></td> </tr> <tr> <td valign="top">Note</td> <td><textarea rows="6" name="Note" cols="50"></textarea></td> </tr> <tr> <td colspan="2" valign="bottom" align="center" height="30"> <input type="submit" value="Invia"> <input type="reset" value="Cancella"> </td> </tr> </table> </form> </body> </html>
con file inviamail.php avente questo codice:
codice:<?php $to = "indirizzo@esempio.com"; $subject = "Test messaggio"; // Corpo del messaggio $body = "Contenuto del modulo:\n\n"; $body .= "Nome: " . trim(stripslashes($_POST["name"])) . "\n"; $body .= "Email: " . trim(stripslashes($_POST["email"])) . "\n"; $body .= "Oggetto: " . trim(stripslashes($_POST["subject"])) . "\n"; $body .= "Messaggio: " . trim(stripslashes($_POST["message"])) . "\n"; $headers = "From: " . trim(stripslashes($_POST["email"])) . "\n"; if(@mail($to, $subject, $body, $headers)) { echo "Messaggio inoltrato con successo."; } else { echo "Errore invio. Riprova!"; } ?>
Se carico questo file sul server remoto tutto bene, l'invio funziona ed è anche veloce.
Ho provato invece a usare questo stesso file PHP collegandolo al seguente pezzo di codice HTML (in una pagina):
codice:<form action="./inviamail.php" method="POST" id="ajax-contact-form"> <input type="text" class="required" size="40" name="name" value="Nome" title="Nome" /> <input type="text" class="required" size="40" name="email" value="Email" title="Email" /> <input type="text" size="40" name="subject" value="Oggetto" title="Oggetto" /> <textarea cols="50" rows="10" name="message" class="required" id="message" title="Messaggio"> Messaggio </textarea> <input type="submit" class="send_btn" value="Invia!"> <input type="reset" class="send_btn" value="Reset"> </form>
Ma non funziona! La pagina precedente si trova (come la pagina di test iniziale) nello stesso folder del file inviamail.php.
Suggerimenti?

Rispondi quotando
