Advertisement
Guest User

Untitled

a guest
Mar 28th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.71 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.     <title>NETTUTS > Sign up</title>
  6.     <link href="css/style.css" type="text/css" rel="stylesheet" />
  7. </head>
  8. <body>
  9.     <!-- start header div -->
  10.     <div id="header">
  11.         <h3>NETTUTS > Sign up</h3>
  12.     </div>
  13.     <!-- end header div -->  
  14.      
  15.     <!-- start wrap div -->  
  16.     <div id="wrap">
  17.          
  18.         <!-- start php code -->
  19.         <?php
  20.         use PHPMailer\PHPMailer\PHPMailer;
  21.         use PHPMailer\PHPMailer\Exception;
  22.  
  23.         //Load Composer's autoloader
  24.         require 'vendor/autoload.php';
  25.           define("DB_USER", "root");
  26.           define("DB_PASSWORD", "");
  27.           define("DB_DATABASE", "akademik");
  28.           define("DB_HOST", "localhost");
  29.           $cn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  30.          
  31.             if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['email']) && !empty($_POST['email'])){
  32.             $name = $_POST['name']; // Turn our post into a local variable
  33.             $email = $_POST['email']; // Turn our post into a local variable
  34.            
  35.             // Return Success - Valid Email
  36.             $msg = 'Your account has been made, <br /> please verify it by clicking the activation link that has been send to your email.';
  37.            
  38.             $hash = md5( rand(0,1000) );
  39.             $password = rand(1000,5000);
  40.            
  41.             mysqli_query($cn,"INSERT INTO users (username, password, email, hash) VALUES('$name',md5('".$password."'),'$email','$hash')");
  42.            
  43.             $to      = $email; // Send email to our user
  44.             $subject = 'Signup | Verification'; // Give the email a subject
  45.             $message = '
  46.              
  47.             Thanks for signing up!
  48.             Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
  49.              
  50.             ------------------------
  51.             Username: '.$name.'
  52.             Password: '.$password.'
  53.             ------------------------
  54.              
  55.             Please click this link to activate your account:
  56.             http://www.yourwebsite.com/verify.php?email='.$email.'&hash='.$hash.'
  57.              
  58.             '; // Our message above including the link
  59.                                  
  60.             $headers = 'From:noreply@yourwebsite.com' . "\r\n"; // Set from headers
  61.            
  62.         $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
  63.         try {
  64.             //Server settings
  65.             $mail->SMTPDebug = 2;                               // Enable verbose debug output
  66.             $mail->isSMTP();                                      // Set mailer to use SMTP
  67.             $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
  68.             $mail->SMTPAuth = true;                               // Enable SMTP authentication
  69.             $mail->Username = 'setiadikindi@gmail.com';                 // SMTP username
  70.             $mail->Password = 'kinkin12';
  71.             $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  72.             $mail->Port = 587;                                    // TCP port to connect to
  73.             $mail->SMTPOptions = array(
  74.                                 'ssl' => array(
  75.                                 'verify_peer' => false,
  76.                                 'verify_peer_name' => false,
  77.                                 'allow_self_signed' => true
  78.                                 )
  79.                             );
  80.  
  81.             //Recipients
  82.             $mail->setFrom('kinsetiadi@gmail.com', 'Mailer');
  83.             $mail->addAddress($email);               // Name is optional
  84.          
  85.  
  86.             //Content
  87.             $mail->isHTML(true);                                  // Set email format to HTML
  88.             $mail->Subject = $subject;
  89.             $mail->Body    = '
  90.             Thanks for signing up! <br/>
  91.             Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.  <br/>
  92.  
  93.             ------------------------ <br/>
  94.             Username: '.$name.' <br/>
  95.             Password: '.$password.' <br/>
  96.             ------------------------ <br/>
  97.  
  98.             Please click this link to activate your account: <br/>
  99.             http://www.yourwebsite.com/verify.php?email='.$email.'&hash='.$hash.'
  100.  
  101.             ';
  102.             $mail->send();
  103.             echo 'Message has been sent';
  104.         } catch (Exception $e) {
  105.             echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  106.         }
  107.  
  108.         }
  109.          
  110.         ?>
  111.         <!-- stop php code -->
  112.      
  113.         <!-- title and description -->  
  114.         <h3>Signup Form</h3>
  115.         <p>Please enter your name and email addres to create your account</p>
  116.          
  117.         <!-- start sign up form -->  
  118.         <form action="" method="post">
  119.             <label for="name">Name:</label>
  120.             <input type="text" name="name" value="" />
  121.             <label for="email">Email:</label>
  122.             <input type="text" name="email" value="" />
  123.              
  124.             <input type="submit" class="submit_button" value="Sign up" />
  125.         </form>
  126.         <!-- end sign up form -->
  127.          
  128.     </div>
  129.     <!-- end wrap div -->
  130. </body>
  131. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement