0

Still learning PHP. I'm trying to practice making a form that mails it's info to an email. I use wampserver and the php never fails to give me an error. Please check it out and tell me if it's an issue from my code or if local servers just can't send emails. I tried "configuring" my wampserver but I ultimately ended up messing my Apache and PHP. So I need help. Here's my HTML

<div class="container">
<div class="col-md-6 wrapper col-md-offset-3">
<h2>Sign Up</h2>
<?php echo $result; ?>
<p class="lead">Please fill in your credentials below: </p>


<form class="form-group" method="post">
 <label for="first_name">First Name</label>
  <input name="first_name" class="form-control" type="text" value="<?php echo $_POST['first_name']; ?>"/>
  <label for ="last_name">Last Name</label>
  <input name = "last_name" class="form-control" type="text" value="<?php echo $_POST['last_name']; ?>"/>
  <label for ="Username">Username</label>
  <input name="Username" class="form-control" type="text" value="<?php echo $_POST['Username']; ?>"/>
  <label for="email">Email</label>
  <input name="email" class="form-control" type="email" value="<?php echo $_POST['email']; ?>"/>
  <label for ="password">Password</label>
  <input name ="password" class="form-control" type="password" value="<?php echo $_POST['password']; ?>"/>
  <label for="confirm_password">Confirm Password</label>
  <input name="confirm_password" class="form-control" type="password" value="<?php echo $_POST['confirm_password']; ?>"/>
  <input type="submit" name="submit" class="form-control btn" id="submit" value="Submit" />
</form>
  <p>Already a user? <a href="#">Sign in</a></p>
  </div>
  </div>
  </body>

And here's my PHP

      <?php
      if ($_POST["submit"]){
      if (!$_POST["first_name"]){
        $error="<br />Please enter your First Name";
      }
      if (!$_POST["last_name"]){
        $error.="<br />Please enter your Last Name";
      }
      if (!$_POST["Username"]){
        $error.="<br />Please enter a Username";
      }
      if (!$_POST["email"]){
        $error.="<br />Please enter an email";

      }  if ($_POST["email"]!= "" AND !filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
          $error.="<br />Please enter a valid email address";
        }
      if (!$_POST["password"]){
        $error.="<br />Please enter a password";
      }
      if (!$_POST["confirm_password"]){
        $error.="<br />Please confirm your password";
      }
      if ($_POST["password"]!=$_POST["confirm_password"]){
        $error.="<br />Please enter matching passwords";
      }
      $result = '<strong style="color:red;"><span>There were error(s) in your form:'.$error.'</span></strong><br />';
      if($error==""){
        $to="eapriok@gmail.com"; $subject="New Member to Chuk's site";
        if( mail($to, $subject, "Name $_POST[\"first_name\"] $_POST[\"last_name\"] and his Username is $_POST[\"Username\"]. Password is $_POST[\"password\"]." )){
          $result='<div class="alert alert-info">You have been signed in successfully. Please wait while we take you to your dashboard</div>';
        }else{
          $result='<div class="alert alert-danger">Something went wrong and we couldn\'t complete the registration. Please try again.</div>';
        }
    }
  }

 ?>

Right now this is the error PHP is throwing to my face, "( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\php\contactform.php on line 56"

I've gotten really frustrated...

Eric McWinNEr
  • 534
  • 6
  • 19
  • Excuse me, are you trying to send emails over your own network or to the whole internet? – statosdotcom Jul 16 '16 at 00:40
  • `"Name $_POST[\"first_name\"] $_POST[\"last_name\"]..."` is invalid. It should be: `"Name $_POST[first_name] $_POST[last_name]..."` etc when you concatenating array variables inside double quotes. Or `"Name {$_POST['first_name']} ..."` which I prefer since it's more readable. – M. Eriksson Jul 16 '16 at 00:42
  • And your form (the HTML-part) will only work if all the `$_POST` data is populated (when the form is already posted). Otherwise you should get a bunch of "undefined index" since you're assuming that the `$_POST`-array have all those keys you're echoing. – M. Eriksson Jul 16 '16 at 00:48
  • I'm trying to send the email over the whole internet statosdotcom. But even if I were to be sending over my network how could I do that? – Eric McWinNEr Jul 17 '16 at 11:03

0 Answers0