Is this safe?

Soldato
Joined
2 May 2004
Posts
19,946
Hi,

Just wondered if this is safe?:

index.php:
normal form, nothing special - just some nice css, submits to sendmail.php

sendmail.php:
Code:
<?
  $name = $_POST['name'];
  $domain = $_POST['domain'];
  $email = $_POST['email'];
  $space = $_POST['space'];
  $bandwidth = $_POST['bandwidth'];
  $dailyUnique = $_POST['dailyUnique'];
  $pageRank = $_POST['pageRank'];
  $description = $_POST['description'];
  
  //CONFIG
  include "config.php"
  
  if(empty($name)){
	echo 'Please make sure you entered your name';
  }
  
  elseif(empty($domain)){
	echo 'Please make sure you entered your domain name';
  }
  
  elseif(empty($email)){
	echo 'Please make sure you entered your email address';
  }
  
  elseif(empty($space)){
	echo 'Please make sure you entered the ammount of space your website requires';
  }
  
  elseif(empty($bandwidth)){
	echo 'Please make sure you entered the ammount of bandwidth your website users';
  }
  
  elseif(empty($dailyUnique)){
	echo 'Please make sure you entered the ammount of unique visitors you get daily';
  }
  
  elseif(empty($description)){
	echo 'Please go back and enter a website description';
  }
  
  else {
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

  $headers .= "From: $name <$email>";
  
  foreach ($_REQUEST as $key => $val) {
	if ($key != "from_email" && $key != "from_name") {
		$body .= $key . " : " . $val . "\r\n";
	}
  }  
  
  if(mail($to, "Sponsor request", $message, $headers)){
	header("Location: ".$thxEmail);
  }
  }
?>

config.php:
Code:
<?

  $to = "[email protected]";
  $thxEmail = "thxEmail.php";
  $message = "<style>body{font-family:Verdana; font-size:10px;}</style>
		 <table border=\"1\" cellspacing=\"2\" cellpadding=\"2\">
			 <tr><td>Name:</td><td>$name</td></tr>
			 <tr><td>Domain name:</td><td> $domain</td></tr>
			 <tr><td>Email address:</td><td> $email</td></tr>
			 <tr><td>Space used:</td><td> $space</td></tr>
			 <tr><td>Bandwidth used:</td><td> $bandwidth</td></tr>
			 <tr><td>Daily uniques:</td><td> $dailyUnique</td></tr> 
			 <tr><td>Page rank:</td><td> $pageRank</td></tr>
			 <tr><td>Description:</td><td> $description</td></tr>
		 </table>";
	
?>

Thanks,
Craig.
 
Last edited:
Man of Honour
Joined
31 Jan 2004
Posts
16,335
Location
Plymouth
That script is better.

The reason yours is unsafe is because baaad content can be injected causing the mail server to send out a few hundred e-mails unbeknown to you.

It's not a matter of making the script public because so long as nothing else can be injected into the e-mail via the other variables you can guarantee that e-mails can only be sent to the address you specify. And that people can't inject Evil Spam Code to send out their spam :)
 
Associate
Joined
30 Dec 2005
Posts
415
It should really have some kind of validation...whether image based or question based to deter scripts from submitting the form repeatedly and putting a load on the server.
 
Back
Top Bottom