Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require "phpMailer/PHPMailer/PHPMailerAutoload.php";
- $mail = new PHPMailer();
- // initializing variables
- $errors = array();
- // connect to the database
- $db = mysqli_connect('localhost', 'servername', 'password', 'gac');
- // REGISTER USER
- if (isset($_POST['reg_user'])) {
- // receive all input values from the form
- $username = mysqli_real_escape_string($db, $_POST['username']);
- $email = mysqli_real_escape_string($db, $_POST['email']);
- $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
- $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now successfully registered";
- // form validation: ensure that the form is correctly filled ...
- // by adding (array_push()) corresponding error unto $errors array
- if (empty($username)) { array_push($errors, "Username is required"); }
- if (empty($email)) { array_push($errors, "Email is required"); }
- if (empty($password_1) || strlen($password_1)<8) { array_push($errors, "Password is required and must be 8 length in characters"); }
- if ($password_1 !== $password_2) {
- array_push($errors, "The two passwords do not match");
- }
- // first check the database to make sure
- // a user does not already exist with the same username email
- $user_check_query = "SELECT * FROM registered_users WHERE email='$email' LIMIT 1";
- $result = mysqli_query($db, $user_check_query);
- $user = mysqli_fetch_assoc($result);
- if ($user) { // if user exists
- /* if ($user['username'] === $username) {
- array_push($errors, "Username already exists");
- }*/
- if ($user['email'] === $email) {
- array_push($errors, "email already exists");
- }
- }
- // Finally, register user if there are no errors in the form
- if (count($errors) == 0) {
- $v_key = md5($email.time());//generate the vkey for database
- $v_addKey = substr(md5(uniqid(rand(),1)),3,8);
- $v_key = $v_addKey.$v_key;
- $password = md5($password_1);//encrypt the password before saving in the database
- //making expiry link for activation of account
- $exp_acc_act_Format = mktime(
- date("H")+1, date("i"), date("s"), date("m") ,date("d"), date("Y")
- );
- $expHour = date("Y-m-d H:i:s",$exp_acc_act_Format);
- $query = "INSERT INTO registered_users (username, email, password, status, v_key, expHour) VALUES('$username', '$email', '$password',0,'$v_key','$expHour')";
- $insert = mysqli_query($db, $query);
- if($insert)// after insert send verification email
- {
- $output='<p>Dear user,</p>';
- $output.='
- <p>Please click on the following button to activate your account.</p>';
- $output.='<center style ="border:1px solid black;height:40px;width:200px;background-color:#005b2d;">
- <p>
- <a href="http://www.sanjeevsanthalia.com/thankyou.php?v_key='.$v_key.'&email='.$email.'&action=reset" target="_blank" style ="color:white;text-decoration:none;">
- <strong>
- Click here to verify the email
- </strong>
- </a>
- </p>
- </center>';
- $output.='<p>Thanks,</p>';
- $body = $output;
- $subject = "Account Activation -GACKONNECT ";
- $email_to = $email;
- $fromserver = "noreply@gacons.com";
- //$mail->IsSMTP();/*by commenting also it was working*/
- $mail->SMTPAuth = true;
- $mail->SMTPSecure = 'ssl';
- $mail->Host = "hello.com"; // Enter your host here
- $mail->Port = 465;
- $mail->Username = "noreply@hello.com"; // Enter your email here
- $mail->Password = "password"; //Enter your password here
- $mail->IsHTML(true);
- $mail->From = "noreply@hello.com";
- $mail->FromName = "GACKONNECT";
- $mail->Sender = $fromserver; // indicates ReturnPath header
- $mail->Subject = $subject;
- $mail->Body = $body;
- $mail->AddAddress($email_to);
- if(!$mail->send()){
- echo "Mailer Error: " . $mail->ErrorInfo;
- }else{
- header('location:afterRegistration.php');
- }
- }
- }
- }
- It was working but suddenly stopped. I am not able to figure out. Receiving data in database also only mail is not sending.
Add Comment
Please, Sign In to add comment