It’s better not to put $_POST inside a class, but you could do it that way. The better way to do it would to do something like the following:
if (($_SERVER['REQUEST_METHOD'] === 'POST') && isset($_POST['submit'])) {
$send = new sendMail();
$data = [];
$data['name'] = $_POST['user']['first_name'] . ' ' . $_POST['user']['last_name'];
$data['validation'] = $send->validationFCN(20);
$_POST['user']['validation'] = $data['validation'];
$data['email'] = $_POST['user']['email'];
$data['phone'] = $_POST['user']['phone'];
$data['birthday'] = $_POST['user']['birthday'];
$data['message'] =
'<html lang="en">' .
'<body style=\'background: #eee;\'>' .
'<p style="font-size: 1.8em; line-height: 1.5;">Full Name : ' . $data['name'] .
'<br>Email Address : ' . $data['email'] .
'<br>Phone : ' . $data['phone'] .
'<br>Birthday : ' . $data['birthday'] . '</p>' .
'<p style="font-size: 1.4em; line-height: 1.5;">Please click on link: https://www.phototechguru.com/admin/activate.php?confirmation=' . $data['validation'] . ' in order to have access to the Miniature Photographer Website.</p>' .
'<p style="font-size: 1.4em; line-height: 1.5;">In addition please answer the question "Meet Me Under the [blank] Clock" with the name of the clock in the image that was sent.</p>' .
'</body>' .
'</html>';
$register = new Register($_POST['user']);
$result = $register->create();
if ($result) {
$send->verificationEmail($data);
header("Location: success.php");
exit();
}
header("Location: register.php");
exit();
}
The goal is to be able to use PHP Classes to your advantage and benifit.
The reason you are getting an error is you are naming variables/classes/whathaveyou the same AND/OR you are NOT loading your class(es) in - (I think, not loading them in?). I’m using a composer autoloader to load my clases:
I recommend autoloading classes (though you can do it manually) and using namespaces that way you don’t have to worry about using the same names. Here’s just one link that I found on autoloading - https://code.tutsplus.com/tutorials/how-to-autoload-classes-with-composer-in-php–cms-35649
require_once "../assets/config/config.php"; // PHP Configurations and stuff:
require_once "../vendor/autoload.php"; // Composer Autoloader
use PhotoTech\Register; // Namespace for that particular class (PhotoTech)
use PhotoTech\sendMail;
you could even do the following
use PhotoTech\Register as Signup;
the class
namespace PhotoTech;
class Register extends DatabaseObject
{
protected static string $table = "admins"; // Table Name:
static protected array $db_columns = ['first_name', 'last_name', 'email', 'username', 'phone', 'security', 'hashed_password', 'validation', 'new_date', 'update_date', 'birthday'];
Hope it helps: