title: PHP Newsletter singup reverse engineer
body: <p>I have the following code that someone before me setup for a newsletter signup system.</p>
  
  <pre><code>error_reporting(0);
  set_magic_quotes_runtime (0);
  if (get_magic_quotes_gpc()) {
  foreach($_POST as $k=&gt;$v)
      $_POST[$k] = stripslashes($v);
  foreach($_COOKIE as $k=&gt;$v)
      $_COOKIE[$k] = stripslashes($v);
  }
  
  $msg = $_COOKIE['sb'.$_GET['id']];
  
  $email = trim($_GET['email']);
  $Ok = ereg("^([a-zA-Z0-9_\.-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email);
  
  $headers  = 'From: ' . $email . "\n"; 
  $headers .= 'MIME-Version: 1.0' ."\n"; 
  $headers .= 'Content-Type: text/plain; charset=iso-8859-1' ."\n"; 
  $headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";
  
  if ($Ok &amp;&amp; ($msg != '')) {
  mail($emailmanager,'Subscribe to Newsletter',$msg,$headers);
  Header("Location: $urlok");
  } else {
  Header("Location: $urlko");
  }
  </code></pre>
  
  <p>A php file is called by submitting the form (email address, name, state, phone number etc) which has this code:</p>
  
  <pre><code>error_reporting(0);
  
  set_magic_quotes_runtime (0);
  if (get_magic_quotes_gpc()) {
  foreach($_POST as $k=&gt;$v)
      $_POST[$k] = stripslashes($v);
  foreach($_COOKIE as $k=&gt;$v)
      $_COOKIE[$k] = stripslashes($v);
  }
  
  $msg = '';
  foreach($_POST as $k=&gt;$v) {
  if (strtolower($k) != "submit" &amp;&amp; trim($v) != '')
      $msg .= "$k:$v\n";
  }
  
  $id = md5($msg);
  setcookie("sb$id",$msg,time()+86400,'','',0);
  
  $email = trim($_POST['email']);
  </code></pre>
  
  <p>It send an email to the person who filled in the form, with a link for them to click to verify their email address.</p>
  
  <p>When they click the link, the first php file (at top) is called that then sends the stored details of the original form to an email address as a message, so the recipient of the email can manually enter these details into a database (mailing list).</p>
  
  <p>I am trying to reverse engineer it so that, instead of sending a notification email to the mailing list manager, it inserts the details into a database.</p>
  
  <p>I am pretty good with manipulating databases with php,but the above code is a bit beyond me.</p>
  
  <p>I'm not sure how the code packs the details of all the inputs of the form into an id, stores until the email address is verified, then puts them all into the email sent to the list manager, but, looking at the code, can anyone see a way to extract those inputs out again, so that I can put them in some variables, ready to insert into my database table?</p>
  
  <p>Any help would be greatly appreciated.
  Thank you in advance.
  Cheers, Al.</p>