Minimal PHP Mailer Script

Here is a step-by-step guide to making a minimal PHP mailer form. This is straightforward, but lacks privacy (i.e., your destination e-mail is exposed to potential spammers), and using PHP at all is somewhat of a security risk. Where security and privacy is required, we recommend using our secure mailer application instead.

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>

Csoft.net
© 2025 CubeSoft Communications
All Rights Reserved.