PHP – Email Sender
DOWNLOAD
You must create in the same folder 2 files:
1. email-form.php -> the email form
2. email-sender.php -> the PHP email sender engine
Simplest Email Sender – No Validation and Security controls
email-form.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <html> <body> <!-- SIMPLE PHP EMAIL SENDER --> <!-- Author: blog.lucedigitale.com - Andrea Tonin --> <!-- FORM START --> <!-- Il form invia a email-sender.php tutti i dati raccolti --> <form method= "post" action= "email-sender.php" > Name: <br> <input type= "text" name= "name" > <br> E-mail: <br> <input type= "text" name= "email" > <br> Comment: <br> <textarea name= "comment" rows= "5" cols= "40" ></textarea> <br><br> <input type= "submit" > </form> <!-- FORM END --> </body> </html> |
email-sender.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <?php // SIMPLE PHP EMAIL SENDER // Author: blog.lucedigitale.com - Andrea Tonin // EDIT THE 2 LINES BELOW AS REQUIRED // email a cui inviare il messaggio e il suo soggetto $email_to = "andreat@lucedigitale.com" ; $email_subject = "New email from your website" ; // $_REQUEST colleziona il dato ricevuto dal form $email_name = $_REQUEST [ 'name' ]; $email_from = $_REQUEST [ 'email' ]; $email_comment = $_REQUEST [ 'comment' ]; $email_content = "\n Name: " . $email_name . "\n Email: " . $email_from . "\n Comment: \n" . "\n" . $email_comment ; // Create email headers // Invio l'email all'indirizzo specificato nella variabile $email_to specificata all'inizio del codice $headers = 'From: ' . $email_name . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail( $email_to , $email_subject , $email_content , $headers ); // Messaggio di avvenuta spedizione, si arriva a questa porzione di codice solo se la parte precedente dello script ha funzionato correttamente echo "Thanks! The mail has been sent successfully!" ; ?> |