Darksat IT Security Forums
November 24, 2017, 07:54:29 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]
  Print  
Author Topic: Simple PHP Mail Script  (Read 1964 times)
Darksat
Administrator
Master
*******
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.

Code:
<head><title>Mail sender</title></head>
<body>
   <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">
   </form>
 </body>
</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.

Code:
<html>
<head><title>PHP Mail Sender</title></head>
<body>
<?php
$to       
"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))
{
     echo 
"   <h3>Sorry all fields are required.</h3>";
}
elseif(!
ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email)) {
     print 
"   <h3>Sorry the email address you entered is not valid.</h3>";
}
else
{
     
mail($to$sub$mes$headers);
     print 
"   Thank you for your email, we will get back to you as soon as possible"
}
?>

</body>
</html>


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

Social Buttons


Pages: [1]
  Print  
 
Jump to:  

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

Buy traffic for your forum/website
traffic-masters
Powered by SMF | SMF © 2016, Simple Machines
Page created in 0.062 seconds with 12 queries.