piano0011
piano0011

Reputation: 35

I need some assistance in making an email activation with php oop syntax

I have almost got my code to work but would prefer to use my user class but when implementing $user = new User() into my registration.php file, it won't work. I have got the following codes so far. This is only part of the code..

<?php
 require_once 'core/init.php';  // we have autoloader here


 if(isset($_POST['submit'])) {

      $random = rand();
      $name = $_POST['name'];
      $email = $_POST['email'];
      $to = '[email protected]';

      $header = 'From: [email protected]';

      $subject = 'Email activation is required';
      $message = <<<EMAIL

      Hello $name How are you? Thank you for registering and please 
      click on the link to activate your account: 
      .http://localhost/pianocourse101/activate.php? 
      email=$_POST['email']

      EMAIL;

      mail($to, $subject, $message, $header);
}

I hope that these are enough codes but will be happy to provide more coding...

I am also getting the following errors when including the activation link http://

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\pianocourse101\register.php on line 17

However, I would prefer to do something like $user->data()->username
but I am not sure how to go about in doing this. I managed to do it in my profile.php but for some reason when I tried it here, it says something about non-object error.. I am not sure what non-object means but I included the $user = new User(); line which should work...I am new to php and would like a simple step by step explanation

if($validation->passed()) {

  $user = new User();

  $salt = Hash::salt(32);


 try {
     $user->create(array(
    'username' => Input::get('username'),
    'password' => Hash::make(Input::get('password'), $salt),
    'salt' => $salt,
    'name' => Input::get('name'),
    'joined' => date('Y-m-d H:i:s'),
    'group' => 0,
    'email' => Input::get('email'),
    'activated' => 0,
    'country' => Input::get('country'),
    'token' => Input::get('token'),
    'email_code' => Hash::make(Input::get('username', microtime()))

     ));



    Session::flash('home', 'You have been registered and can now log in!');
   // Redirect::to('index.html');


    } catch(Exception $e) {
      die($e->getMessage());
    }
 } else {
    foreach($validation->errors() as $error) {
      echo $error, '<br>';
    }
 }





<form action="" method="post" id="simpleform">
<div class ="field">      
<label for="username">Username</label>
<input type="text" name="username" id="username" value="<?php echo 
escape(Input::get('username')); ?>" autocomplete="off">
</div>

Upvotes: 1

Views: 58

Answers (1)

Syscall
Syscall

Reputation: 19764

You Heredoc format is not good. The close element must not be indented:

    $message = <<<EMAIL

         Hello $name How are you? Thank you for registering and please 
         click on the link to activate your account: 
         .http://localhost/pianocourse101/activate.php? 
         email=$_POST['email']

EMAIL; // on the first column

From documentation:

It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.

Upvotes: 3

Related Questions