Formulaire e-mail minimal

Here is a step-by-step guide to making a minimal PHP mailer form.

Writing the mailer script

Using your favorite text editor, create a new PHP script (say fmail.php), as follows:

<?php
$TO = "yourname@domain.ext";
 
$h  = "From: " . $TO;
$message = "";
while (list($key, $val) = each($HTTP_POST_VARS)) {
  $message .= "$key : $val\n";
}
mail($TO, $subject, $message, $h);
 
Header("Location: http://yourdomain.ext/thankyou.html");
?>

Replace yourname@domain.ext by your own e-mail address, and replace the URL in the Header() call by whichever page you want the visitor to be redirected to on success.

Writing the HTML form

You can now invoke the mailer script using the following HTML code.

<form method=POST action=fmail.php >
<input type=hidden name=subject value=formmail>
<table>
<tr><td>Your name:</td>
    <td><input type=text name=realname size=30></td></tr>
<tr><td>Your email:</td>
    <td><input type=text name=email size=30></td></tr>
<tr><td>Subject:</td>
    <td><input type=text name=title size=30></td></tr>
<tr><td colspan=2>Comments:<br>
  <textarea COLS=50 ROWS=6 name=comments></textarea>
</td></tr>
</table>
<br> <input type=submit value=Send> -
     <input type=reset value=Reset>
</form>

Ce site web - © 2012 Hébergement Csoft.net, Inc.
(Nous Rejoindre) (Politique de Confidentialité)
  LPF Valid HTML 4.01 Transitional