Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'dbconnect.php';
- require 'PHPMailer/PHPMailerAutoload.php';
- $mail = new PHPMailer;
- $npsn = $_POST['npsn'];
- $error = false;
- // basic npsn validation
- if (empty($npsn)) {
- echo "<script>alert('Anda belum memasukkan NPSN Sekolah Anda!'); window.location = 'lupapassword.php'</script>";
- } else if (!preg_match("/^[0-9]+$/",$npsn)) {
- echo "<script>alert('NPSN hanya boleh diisi Angka saja!'); window.location = 'lupapassword.php'</script>";
- }else if (strlen($npsn) < 8) {
- echo "<script>alert('NPSN harus 8 Angka!'); window.location = 'lupapassword.php'</script>";
- }else {
- // check npsn exist or not
- $query = "SELECT npsn FROM users WHERE npsn='$npsn'";
- $result = mysql_query($query);
- $count = mysql_num_rows($result);
- if($count<1){
- echo "<script>alert('Maaf, NPSN Sekolah Anda tidak ditemukan!'); window.location = 'lupapassword.php'</script>";
- }else {
- // check email exist or not
- $query2 = "SELECT email_sekolah FROM users WHERE npsn='$npsn'";
- $result2 = mysql_query($query2);
- $count2 = mysql_num_rows($result2);
- if($count2<1){
- echo "<script>alert('Maaf, sebelumnya anda belum mengisi email sekolah pada data sekolah. Password tidak bisa dikirimkan. Silahkan hubungi admin!'); window.location = 'lupapassword.php'</script>";
- }
- }
- // if there's no error, continue to signup
- if( !$error ) {
- $query = "SELECT * from users WHERE npsn=$npsn";
- $hasil = mysql_query($query);
- $data = mysql_fetch_array($hasil);
- $email = $data['email'];
- $password = $data['password'];
- // Konfigurasi SMTP
- $mail->isSMTP();
- $mail->Host = 'smtp.gmail.com';
- $mail->SMTPAuth = true;
- $mail->Username = 'myemail@gmail.com';
- $mail->Password = 'mypass';
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
- $mail->setFrom('myemail@gmail.com', 'Irmanto');
- $mail->addReplyTo('myemail@gmail.com', 'Irmanto');
- // Subjek email
- $mail->Subject = 'Password Member Area';
- // Mengatur format email ke HTML
- $mail->isHTML(true);
- // Konten/isi email
- $mailContent = "<p>my message</p>";
- $mail->Body = $mailContent;
- // Menambahkan penerima
- $mail->addAddress($email);
- // Kirim email
- if(!$mail->send()){
- echo 'Maaf, Password tidak bisa dikirim. </br>Silahkan hubungi admin!';
- echo '</br></br>Error: ' . $mail->ErrorInfo;
- }else{
- echo "<script>alert('Password telah dikirim ke $email!'); window.location = 'index.php'</script>";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement