Your browser does not seem to support CSS. If images appear below, please disregard them.
It appears that you're running an Ad-Blocker. This site is monetized by Advertising and by ">User Donations; we ask that if you find this site helpful that you whitelist us in your Ad-Blocker, or make a ">Donation to help aid in operating costs.
Previous Thread
Next Thread
Print Thread
Rate This Thread
#18089 - 11/01/04 02:33 AM PHP Mail Script  
Joined: Jun 2003
Posts: 807
Ghost Offline
UGN Super Poster
Ghost  Offline
UGN Super Poster

Joined: Jun 2003
Posts: 807
Likes: 2
Wisconsin
A little mail script i wrote that tells you when you didn't fill out a field, and allows you to ban ip addresses from viewing the page. Any suggestions for optimizations, additions, or removals? Comments?
Code
<?php
# Ghost's PHP Mail Script v1.3
# The source from this script may be freely distributed so long as credit is given
$ip = $_SERVER['REMOTE_ADDR'];
$banfile = fread(fopen("banip.txt", "r"), filesize("banip.txt"));
$file = fopen("maillog.txt", "a+");
$address = $_SERVER['REMOTE_ADDR'];
$mailaddress = $_POST['address'];
$subject = $_POST['subject'];
$from = $_POST['from'];
$message = $_POST['message'];
$submitted = $_POST['submitted'];
fwrite($file, "Page View: \n $address \n\n");
if(strstr($banfile, "$ip")) {
die("Banned.");
};
if(strpos($mailaddress, "@") && strpos($from, "@") && $subject !== NULL && $message !== NULL) {
fwrite($file, "Message: \n $address \n  $mailaddress \n $date \n $message \n\n");
mail($mailaddress, $subject, $message,
"Return-Path: $from\n" .
"From: $from\n" .
"X-Sent-With: Ghost's PHP Mail Sender v1.4");
echo "Your mail has been sent";
} elseif($submitted == "1") {
if(!strpos($mailaddress, "@")) {
echo "You need to input an address for the \"Address\" field.
";
};
if($subject == NULL) {
echo "You need to input a subject for the \"Subject\" field.
";
};
if(!strpos($from, "@")) {
echo "You need to input an address for the \"Return Address\" field.
";
};
if($message == NULL) {
echo "You need to input a message to send in the \"Message\" field.
";
};
echo "
<html>
 <head>
  <title>Mail Page</title>
 </head>
 <body>
  <form action=\"mail.php\" method=\"post\">
   Address: <input type=\"text\" name=\"address\">

   Subject: <input type=\"text\" name=\"subject\">

   Return Address: <input type=\"text\" name=\"from\">

   Message: <textarea name=\"message\"></textarea>

   <input type=\"hidden\" name=\"submitted\" value=\"1\">
   <input type=\"submit\">
  </form>
 </body>
</html>
";
} else {
echo "
<html>
 <head>
  <title>Mail Page</title>
 </head>
 <body>
  <form action=\"mail.php\" method=\"post\">
   Address: <input type=\"text\" name=\"address\">

   Subject: <input type=\"text\" name=\"subject\">

   Return Address: <input type=\"text\" name=\"from\">

   Message: <textarea name=\"message\"></textarea>

   <input type=\"hidden\" name=\"submitted\" value=\"1\">
   <input type=\"submit\">
  </form>
 </body>
</html>
"; };
?>

Sponsored Links
#18090 - 11/01/04 02:35 AM Re: PHP Mail Script  
Joined: Sep 2002
Posts: 390
Shinobi Offline
UGN Member
Shinobi  Offline
UGN Member

Joined: Sep 2002
Posts: 390
Asheville, NC
Wow ghost, why don't you show off a little BIT!?!!???


"The secret to creativity is knowing how to hide your sources."
-Albert Einstein

Tech Ninja Security
#18091 - 11/01/04 03:11 AM Re: PHP Mail Script  
Joined: Feb 2002
Posts: 7,202
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,202
Likes: 11
Portland, OR; USA
Ask me when I'm sober, I have a few pointers :hicup: should be tomorrow or somethig


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#18092 - 11/01/04 04:13 AM Re: PHP Mail Script  
Joined: Jun 2003
Posts: 807
Ghost Offline
UGN Super Poster
Ghost  Offline
UGN Super Poster

Joined: Jun 2003
Posts: 807
Likes: 2
Wisconsin
Haha, all right gizmo, i'll bug you on irc.

#18093 - 11/01/04 02:28 PM Re: PHP Mail Script  
Joined: Feb 2002
Posts: 7,202
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,202
Likes: 11
Portland, OR; USA
How I'd handle listing my calls in a script:
Code
<?php
if($_SERVER["HTTPS"] == "on") {
  $type = "https";
}else{
  $type = "http";
}
$host = $_SERVER["HTTP_HOST"];
$url = "$type://$host/";
$me = $_SERVER["SCRIPT_URL"];
?>

<a href="<?php echo($ssl); ?>://<?php echo($host); ?><?php echo($me); ?>?function=call">link to script</a>
That way it'll auto update the script name and if it's being accessed through https or not; however as it's a mail script you don't really NEED ssl support so that'd knock us down to:
Code
<?php
$host = $_SERVER["HTTP_HOST"];
$me = $_SERVER["SCRIPT_URL"];
?>

<a href="http://<?php echo($host); ?><?php echo($me); ?>?function=call">link to script</a>
Or even:
Code
<?php
$script = $_SERVER["SCRIPT_URI"]
?>

<a href="<?php echo($script); ?>?function=call">link to script</a>
However I woudln't reccommend using the final one for subdomains; for some reason "script_uri" doesn't like subdomains in some enviroments (oen of the manyt hings i had to fix in the fserv)


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Sponsored Links

Member Spotlight
Gremelin
Gremelin
Portland, OR; USA
Posts: 7,202
Joined: February 2002
Show All Member Profiles 
Forum Statistics
Forums45
Topics33,706
Posts68,856
Members2,166
Average Daily Posts0
Members2,166
Most Online1,567
Apr 25th, 2010
Latest Postings
The History Thread...
by Gremelin on 08/11/17 07:11 PM
my old account still exists!
by Gremelin on 08/11/17 07:02 PM
My friend NEEDS your HELP!
by Lena01 on 07/21/17 07:06 AM
I'm having fun with this guy.
by gabithompson730 on 07/20/17 08:50 AM
I want to upgrade my phone
by gabithompson730 on 07/20/17 08:49 AM
Newbie here
by gabithompson730 on 07/20/17 08:46 AM
Blackbeard.....
by Gremelin on 01/14/17 07:03 PM
Top Posters(All Time)
UGN Security 41,392
Gremelin 7,202
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Liked Users (All Time)
§intå× Likes: 3
Black Beard Likes: 1
Cold Sunn Likes: 1
Crime Likes: 1
Cyrez Likes: 1
fleshwound Likes: 1
Ghost Likes: 2
Gremelin Likes: 12
Ice Likes: 1
ninjaneo Likes: 1
Top Liked Users (30 Days)
No Data Found