Ronald B Stamets Website Design and Development Corner of logo

Ronald B Stamets, Web Site Design and Development Services

top content bar
Home Website design Domains & Hosting E-Commerce Additional Services Contact Us About Us Web Design Tutorials FAQ Pay Bill Site Map Request Estimate

Wrapping up hidden email address email form

Now we are going to wrap it up. This is the file that does all of the work. It checks to make sure the form fields are filled in, checks to see if the data came from the form, removes malicious tags, and sends an email to you and your visitor.... Whew!

It is a lot of code, but I have commented it profusely so if you follow the comments you will see what it is doing for you.

Open the email_form_2 file in your forms folder and copy and paste the code below into it. Then save it.

Change the email addresses where indicated so they go to you instead of cyberspace.


<?php // Start parsing PHP
include ('form_output_fns.php'); // Get the functions running and accessible

/*Check and make sure the values came from the form. This allows the form to operate on systems with register globals on or off   BUT ONLY WORKS WITH PHP  version 4.1+*/
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$subject = $_POST['subject'];
$e_mail = $_POST['e_mail'];
$content = $_POST['content'];

//Break up malicious code by removing common code structures
$f_name=eregi_replace ("\.exe", "", $f_name);
$l_name=eregi_replace ("\.exe", "", $l_name);
$subject=eregi_replace ("\/", "", $subject);
$e_mail=eregi_replace ("\.exe", "", $e_mail);
$content=eregi_replace ("\.exe", "", $content);
$f_name=eregi_replace ("\/", "", $f_name);
$l_name=eregi_replace ("\/", "", $l_name);
$subject=eregi_replace ("\/", "", $subject);
$e_mail=eregi_replace ("\/", "", $e_mail);
$content=eregi_replace ("\/", "", $content);



?> <!-- Stop Parsing Php and switch back to good ol html to set up the page tags -->
<html>
<head>
</head>
<body>

<!-- We are done with HTML so start the PHP parser again -->
<?php

/*Now Validate the legimate input by creating a main error block of code to make sure that all of the required fields contain a value */
if (!$f_name || !$l_name || !$subject || !valid_email($e_mail) || !$content)
{
// Start main code block

    if (!$f_name){ // Each of these if's are sub code blocks inside the main block.
    echo "Your <b>First Name</b> is missing.<br>";
    }
    if (!$l_name){
    echo "Your <b>Last Name</b> is missing.<br>";
    }
    if (!valid_email($e_mail)){
    echo "Please double check your <b>Email Address</b>.<br>";
    }
    if (!$subject){
    echo "You need to include the <b>Subject</b> of the email.<br>";
    }
    if ($content==""){
    echo "There is no message in the <b>Body</b>.";
    }

// Since everything in this main block represents a problem, re display the form
display_email_form($f_name,$l_name,$e_mail,$subject,$content);
exit;
// Then stop any more of the application from running.
} // End the main error code block


////////////////////////////////////////////////////////////////////////////
//If all of the validation passes above, we will process the data.
////////////////////////////////////////////////////////////////////////////


// Give the visitor an instant confirmation on screen.

echo "<h3>$f_name- Your message has been sent. <br / >Please check your $e_mail mailbox</h3>";

echo " Sender: $f_name $l_name<br>";

echo "Reply To: $e_mail<br>";
echo "Subject: $subject<br>";
echo "Your Message: $content<br>";



//send confirming email
//This is what you want sent to you, so change it to your email address

$receiver1 = "yoursite@yourplace.com"; // Change this email to your address
$subject1 = "An Email Request from $f_name $l_name";
$message1 .= "Visitor: $f_name $l_name\n";
$message1 .= "Subject: $subject\n";
$message1 .= "Email: $e_mail\n";
$message1 .= "Email Message: $content\n\n";

$message1 .= "$f_name - Notice that nowhere along the line did your email address ever appear to anyone. Reason? When You clicked Send Email, your server sent the message internally. Nowhere was your real address ever revealed. Nice Huh?\n\n";
$headers1 = "
From:MY Email Form\r\n"; // Change this to your id prefernce
mail ($receiver1, $subject1, $message1, $headers1);
unset ($receiver1, $subject1, $message1, $headers1);
// NOTE:  You can add more message1's or modify the text in the existing message1's.  Just be sure to not lose any quotes or periods.   Same with message2's below.


//To the visitor to confirm the email was sent
$receiver2 = "$e_mail";
$subject2 = "Email Confirmation";

$message2 .= "$f_name- This is an automated confirmation that your email has been received by My email Form.\n"; // Change My email form to your identity
$message2 .= "Thank you for working through our email tutorial.\n\n"; // Change this to reflect your message
$message2 .= "Your Message: $content\n\n";

$message2 .= "----------------------------------------------\n";
$message2 .= "Please do not reply to this message. To contact us email us at
MY EMAIL FORM\n"; //Change the MY EMAIL FORM to the address you want visitors to email.
$message2 .= "----------------------------------------------\n";



$headers2 = "From:MY Email Form\r\n"; // Change this too

mail ($receiver2, $subject2, $message2, $headers2);
unset ($receiver2, $subject2, $message2, $headers2);
?>
<!-- End the PHP and wrap up the html code to close the page -->
</body>
</html>
<<< Page 4 Page 6 >>>
home
 
Website Design
 
Domains Hosting
 
ECommerce
 
addl services
   
Contact Us
 
About Us
 
Tutorials
 
Design FAQ
 
Pay Bill
 
site map