Are you tired of spam? Welcome to the free MAILME service!

Here I'll show you how to create a mail form on your own server if you don't like submitting our server your email address. Pretty much the same system is used for this site, through at this site MySQL-database is used to keep user information and there are some more cool but not needed features. I'll go step-by-step and explain the important things. You can copy the whole source needed at the bottom. Important: Your server needs to have PHP installed (and I guess that at least version 4 is needed).

mail.html - The mail form
All simple HTML form. No need to explain. This is only part of a full HTML page.

<textarea name="HTML" cols=65 rows=8>
<form action="send.php" method="POST">
    <input type="hidden" name="id" value="2">
    Your email address*: <input type="text" name="email" size="25"><br>
    <textarea name="content" cols=50 rows=20></textarea><br>
    <input type="submit" value="Send Email">
* This is the email address we can reply to you through

send.php - Mail script
Now let's get into the real deal. I comment with //.

    if($HTTP_POST_VARS) {extract($HTTP_POST_VARS, EXTR_PREFIX_SAME, "post_");}
    if($HTTP_GET_VARS) {extract($HTTP_GET_VARS, EXTR_PREFIX_SAME, "get_");}
    if($HTTP_COOKIE_VARS) {extract($HTTP_COOKIE_VARS, EXTR_PREFIX_SAME, "cookie_");}
    if($HTTP_ENV_VARS) {extract($HTTP_ENV_VARS, EXTR_PREFIX_SAME, "env_");}
    // This makes sure that the PHP page get's all the variables. Not all of the above commands is needed but is nice to have if you built more into this (like using cookies)

$id = addslashes($_POST['content'];
$content = addslashes($_POST['content'];
$email = addslashes($_POST['email']);
// addslashes add security, here we load in all the POST variables we need (these are posted from the mail.html page)

if((preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email) || preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) AND $email != ""){
// this secures that a valid email address is entered. You could built in DNS check but that would probably be overload for just a simple mailing system

    $message = "Someone has sent you a message. The message are as follow:

    // this will be you content of the mail. We strip slashes so it looks nicer

        $emailto = "";
        $error = false;
        $emailto = "";
        $error = false;
        $error = true;
    // Now there is a billion ways to make this much clever, but I made it simple for easy understanding. You just change the id tag in mail.html to make it send to other emails

        mail("$emailto", "Mail sent from mail form", "$message", "From: $email");
        // The syntax is to, subject, content and aftwards special tags

        $returntext = "Mail has been sent!";

        $returntext = "An error occured while sending the mail! Please try again later.";

echo "<html>
<title>Mail sent</title>

Now this is a very simple system, but it pretty much gives the basics. It's very easy to configure such a system and is very rewarding, as you won't have to show your email address in public places anymore. Feel free contact me if you have any questions about this system. Many other tutorials/scripts would probably give more advanced features and better guidelines so search the web if this isn't sufficient!

NB: Color coding is a rip-off of the excellent editor BBEdit :)

[Return to main page]