<?php

  $errorsAndAlerts = "";
  $formErrors      = "";
  
  $_REQUEST['e'] = @$_REQUEST['send'];
  @list($first_name, $last_name) = explode(" ", @$_REQUEST['fullname'], 2);
  $_REQUEST['fn']    = @$first_name;
  $_REQUEST['ln']    = @$last_name;
  $_REQUEST['p']     = @$_REQUEST['phone'];
  $_REQUEST['lists'] = array();
  
  foreach(mysql_select("_nlb_lists", "`database_query` != '1'") as $list) { // set to all lists
    $_REQUEST['lists'][] = $list['num'];
  }
  
  
  
  // process form
  if (@$_REQUEST['submitForm']) {

    // error checking
    
    if(@$_REQUEST['email'])                    { $formErrors = "You entered something in the hidden field. Are you a spam bot?<br>"; }
    if (!@$_REQUEST['fullname'])                { $formErrors .= "You must enter your full name!<br/>\n"; }
    if (!@$_REQUEST['phone'])                   { $formErrors .= "You must enter your phone number!<br/>\n"; }
    if (!@$_REQUEST['send'])                   { $formErrors .= "You must enter your email!<br/>\n"; }
    else if(!isValidEmail(@$_REQUEST['send'])) { $formErrors .= "Please enter a valid email (example: user@example.com)<br/>\n"; }
    if (!@$_REQUEST['message'])                 { $formErrors .= "You must enter a message!<br/>\n"; }

    // send email user
    if (!$formErrors) {
      
      $from    = $_REQUEST['send'];
      $to      = "email@domain.com.au";
      $subject = "Email form submitted from {$_SERVER['HTTP_HOST']}";
      $message = <<<__TEXT__
You've received an email from the email form here:
http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}

Full name: {$_REQUEST['fullname']}
Email:     {$_REQUEST['send']}
Phone:     {$_REQUEST['phone']}
Message:   {$_REQUEST['message']}

The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.
__TEXT__;
      // Note: The above line must be flush left or you'll get an error
      // This is a PHP heredoc.  See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

      // send message
      $mailErrors = sendMessage(array(
        'to'       =>  $to,
        'from'     =>  $from,
        'subject'  =>  $subject,
        'text'     =>  $message,
      ));
      
      
      //$mailResult = @mail($to, $subject, $message, "From: $from");
      if ($mailErrors) { die("Mail Error: $mailErrors"); }
      
      list($errorsAndAlerts, $lists, $authUserNum, $authUserEmail) = nlb_frontend_dispatcher3();


      //
      $errorsAndAlerts .= "Thank you!";
      $_REQUEST = array(); // clear form values
    }

  }
  else {
    $errorsAndAlerts = $formErrors;
  }

?>

<form method="POST" action="" class="registerForm">
    <input type="hidden" name="submitForm" value="1" />
    <input type="hidden" name="n" value="<?php echo htmlencode(@$_REQUEST['n']); ?>" /><?php // subscriber num ?>
    <input type="hidden" name="a" value="<?php echo htmlencode(@$_REQUEST['a']); ?>" /><?php // subscriber authkey ?>
    <input style="display:none;" type="text" name="email" value="" /><?php // hidden for spam ?>

  <?php if (@$errorsAndAlerts): ?>
    <div class="alert"><?php echo $errorsAndAlerts; ?></div>
  <?php endif ?>

<table border="0" cellspacing="0" cellpadding="2">
 <tr>
  <td width="150">Full Name:</td>
  <td><input type="text" name="fullname" value="<?php echo htmlspecialchars(@$_REQUEST['fullname']); ?>" size="50" /></td>
 </tr>
 <tr>
  <td width="150">Email:</td>
  <td><input type="text" name="send" value="<?php echo htmlspecialchars(@$_REQUEST['send']); ?>" size="50" /></td>
 </tr>
 <tr>
  <td width="150">Phone:</td>
  <td><input type="text" name="phone" value="<?php echo htmlspecialchars(@$_REQUEST['phone']); ?>" size="50" /></td>
 </tr>
 <tr>
  <td width="150">Message:</td>
  <td><textarea name="message" rows="5" cols="55"><?php echo htmlspecialchars(@$_REQUEST['message']); ?></textarea></td>
 </tr>
 
 
 <tr>
  <td colspan="2" align="center">
    <br/>
    <input type="submit" name="submit" value="Send Message &gt;&gt;">
  </td>
 </tr>
</table>

</form>

