Darksat IT Security Forums
January 19, 2021, 06:46:38 pm
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Darksat IT Security Forum
From Firewall Support, AntiVirus Questions, Spyware problems, Linux and Windows Security, Black Hat SEO right down to Website Design and Multimedia
  Home Help Search Gallery Links Staff List Login Register  

Simple PHP Mail Script

Pages: [1]
Author Topic: Simple PHP Mail Script  (Read 2083 times)
Posts: 3303

View Profile WWW
« on: August 18, 2006, 05:07:25 am »

PHP is a server-side embedded scripting language used to create dynamic web pages.
In a HTML page, PHP code is enclosed within special PHP tags. When a visitor opens the page, the server processes the PHP code and then sends the output in HTML to the visitor's browser.

Simple PHP email script

First, make the form page email.html or whatever name you want.
you can embed this form in any page.

<head><title>Mail sender</title></head>
   <form method="post" action="email.php">
    Name:<br><input name="name" type="text" size="30"><br><br>
    Email:<br><input name="email" type="text" size="30"><br><br>
    Comments:<br><input name="subject" type="text" size="30"><br><br>
    Message:<br><textarea name="msg" cols="25" rows="6"></textarea><br><br>
    <input type="reset" value="Reset"> <input type="submit" value="Send">
</html> <html>

The form contains the necessary text fields Email, Subject, Message, and the Send button. The line
<form action="email.php" method="POST">
tells the browser to submit the data to the mail.php page for processing.
The email.php page has the following code in it.

<head><title>PHP Mail Sender</title></head>
"you@where-ever.com"// change to your email address
$name     $_POST['name'];
$email    $_POST['email'];
$subject  $_POST['subject'];
$msg      $_POST['msg'];
$d        date('l dS \of F Y h:i:s A');
$sub      "form to mail";
$headers  "From: $name <$email>\n";  
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes      "Subject: ".$subject."\n";
$mes     .= "Message: ".$msg."\n" ;
$mes     .= "Name: ".$name."\n";
$mes     .= 'Email: '.$email."\n";
$mes     .= 'Date & Time: '.$d;

if (empty(
$name) || empty($email) || empty($subject) || empty($msg))
"   <h3>Sorry all fields are required.</h3>";
ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email)) {
"   <h3>Sorry the email address you entered is not valid.</h3>";
"   Thank you for your email, we will get back to you as soon as possible"


You can use this script to create a Contact Us page on your website. Your visitors will be able to send you a message, but your email address won't be shown on the page and spam bots, that search pages looking for email addresses, won't find it.

Just remove you@where-ever.com field from the form and replace it with your email.

« Last Edit: August 18, 2006, 05:14:31 am by Darksat » Report Spam   Logged

Share on Facebook Share on Twitter

Pages: [1]
Jump to:  

Powered by EzPortal
eXTReMe Tracker
Security Forum
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy
Page created in 0.031 seconds with 16 queries.