try{
$stmt = $conn->prepare("INSERT INTO users (email, password, firstname, lastname, activate_code, created_on) VALUES (:email, :password, :firstname, :lastname, :code, :now)");
$stmt->execute(['email'=>$email, 'password'=>$password, 'firstname'=>$firstname, 'lastname'=>$lastname, 'code'=>$code, 'now'=>$now]);
$userid = $conn->lastInsertId();
$message = "
<h2>Thank you for Registering.</h2>
<p>Your Account:</p>
<p>Email: ".$email."</p>
<p>Password: ".$_POST['password']."</p>
<p>Please click the link below to activate your account.</p>
<a href='http://localhost/ecommerce/activate.php?code=".$code."&user=".$userid."'>Activate Account</a>
";
//Load phpmailer
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'iam4759@gmail.com';
$mail->Password = 'mysourcepass';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('iam4759@gmail.com');
//Recipients
$mail->addAddress($email);
$mail->addReplyTo('iam4759@gmail.com');
//Content
$mail->isHTML(true);
$mail->Subject = 'Pet centre';
$mail->Body = $message;
$mail->send();
unset($_SESSION['firstname']);
unset($_SESSION['lastname']);
unset($_SESSION['email']);
$_SESSION['success'] = 'Account created. Check your email to activate.';
header('location: signup.php');
}
catch (Exception $e) {
$_SESSION['error'] = 'Message could not be sent. Mailer Error: '.$mail->ErrorInfo;
header('location: signup.php');
}