Secure Your Contact Email for Your Projects

You should never put your actual email on any page as a way to contact you.

There are a couple of ways to do this. You can use the following with a free service like GitHub instead of CodePen. I would suggest getting used to and using GitHub over CodePen. It works like CodePen and it’s free for public repos.

The reason being that one of the main things you will have to learn for any coding career is how to use Git. Git is built right into GitHub and you can also use more languages than you can on CodePen.

You should never put your actual email on any page as a way to contact you. Here is a secure way of creating a contact method for your page(s).

Create a file called “mail.php”, put it into your root folder, and call it from your page. Put the following code in the “mail.php” file and put your email inside the quotes on the first line. Don’t change anything else.

    // put your desired email address inside the quotes
    $firstname = $_POST["fname"];
    $email= $_POST["email"];
    $text= $_POST["message"];
    $phone= $_POST["phone"];

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "From: " . $email . "\r\n"; // Sender's E-mail
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $message ='<table style="width:100%">
            <td>'.$firstname.'  '.$laststname.'</td>
        <tr><td>Email: '.$email.'</td></tr>
        <tr><td>phone: '.$phone.'</td></tr>
        <tr><td>Text: '.$text.'</td></tr>

    if (@mail($to, $email, $message, $headers))
        echo 'The message has been sent.';
        echo 'failed';


Another Method
You can also do this if you have your own Web Host and upload the file.

Yet Another Method

Another way to accomplish this is to use the free service, FormSpree. They have everything that you need.

*** I would like to thank @JohnnyBizzel for his input.

Pass this along to everyone so they can keep their email secure from spam, hackers, etc.



What if you don’t use PHP?

You don’t have to know PHP. There is nothing more you need.

Actually you need the server you host this file on to be running PHP.
PHP is not native to browsers.

1 Like

I know. You would have to have your own host, which you need anyway.

You don’t need your own host if you use free services like Glitch, Heroku, Github.
For mail you can use formspree
This has been discussed on the forum before:

*There is a reason this is “free” code camp. Paying for things should not be a barrier to learning.

Thanks geekysmurf
for sharing this…this really helps me a lot in my project.

Custom software development company

I have updated this post thanks to @JohnnyBizzel

1 Like