Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <?php
  2. include 'dbconnect.php';
  3. require 'PHPMailer/PHPMailerAutoload.php';
  4.  
  5. $mail = new PHPMailer;
  6.  
  7. $npsn = $_POST['npsn'];
  8. $error = false;
  9. // basic npsn validation
  10. if (empty($npsn)) {
  11. echo "<script>alert('Anda belum memasukkan NPSN Sekolah Anda!'); window.location = 'lupapassword.php'</script>";
  12. } else if (!preg_match("/^[0-9]+$/",$npsn)) {
  13. echo "<script>alert('NPSN hanya boleh diisi Angka saja!'); window.location = 'lupapassword.php'</script>";
  14. }else if (strlen($npsn) < 8) {
  15. echo "<script>alert('NPSN harus 8 Angka!'); window.location = 'lupapassword.php'</script>";
  16. }else {
  17. // check npsn exist or not
  18. $query = "SELECT npsn FROM users WHERE npsn='$npsn'";
  19. $result = mysql_query($query);
  20. $count = mysql_num_rows($result);
  21. if($count<1){
  22. echo "<script>alert('Maaf, NPSN Sekolah Anda tidak ditemukan!'); window.location = 'lupapassword.php'</script>";
  23. }else {
  24. // check email exist or not
  25. $query2 = "SELECT email_sekolah FROM users WHERE npsn='$npsn'";
  26. $result2 = mysql_query($query2);
  27. $count2 = mysql_num_rows($result2);
  28. if($count2<1){
  29. 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>";
  30. }
  31. }
  32. // if there's no error, continue to signup
  33. if( !$error ) {
  34. $query = "SELECT * from users WHERE npsn=$npsn";
  35. $hasil = mysql_query($query);
  36. $data = mysql_fetch_array($hasil);
  37. $email = $data['email'];
  38. $password = $data['password'];
  39.  
  40. // Konfigurasi SMTP
  41. $mail->isSMTP();
  42. $mail->Host = 'smtp.gmail.com';
  43. $mail->SMTPAuth = true;
  44. $mail->Username = 'myemail@gmail.com';
  45. $mail->Password = 'mypass';
  46. $mail->SMTPSecure = 'tls';
  47. $mail->Port = 587;
  48. $mail->setFrom('myemail@gmail.com', 'Irmanto');
  49. $mail->addReplyTo('myemail@gmail.com', 'Irmanto');
  50. // Subjek email
  51. $mail->Subject = 'Password Member Area';
  52.  
  53. // Mengatur format email ke HTML
  54. $mail->isHTML(true);
  55.  
  56. // Konten/isi email
  57. $mailContent = "<p>my message</p>";
  58.  
  59. $mail->Body = $mailContent;
  60.  
  61. // Menambahkan penerima
  62.  
  63. $mail->addAddress($email);
  64.  
  65. // Kirim email
  66. if(!$mail->send()){
  67. echo 'Maaf, Password tidak bisa dikirim. </br>Silahkan hubungi admin!';
  68. echo '</br></br>Error: ' . $mail->ErrorInfo;
  69. }else{
  70. echo "<script>alert('Password telah dikirim ke $email!'); window.location = 'index.php'</script>";
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement