Skip to main content

PHP#32MySQL#28 - Ajax3 + EMAIL

//connect.php

<?php
$link=@mysqli_connect("localhost","root","") or die("Khong the ket noi den server");
mysqli_select_db($link,"webtintuc") or die ("Kiem tra lai ten database!");
mysqli_query($link,"set names 'utf8'");
?>

//dangky.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="xuly_dangky.php">
  <p>
    <label for="hoten">Họ tên:</label>
    <input type="text" name="hoten" id="hoten">
  </p>
  <p>
    <label for="diachi">Dia chi:</label>
    <input type="text" name="diachi" id="diachi">
  </p>
  <p>
    <label for="username">Username:</label>
    <input type="text" name="username" id="username">
  </p>
  <p>
    <label for="pass">Password:</label>
    <input type="text" name="pass" id="pass">
  </p>
  <p>
    <label for="email">Email:</label>
    <input type="text" name="email" id="email">
  </p>
  <p>
    <input type="submit" name="dangky" id="dangky" value="Đăng ký">
  </p>
</form>
</body>
</html>

//xuly_dangky.php

<?php
if(isset($_POST['dangky']))
{
include("connect.php");
$ngaydk=date("Y-m-d",time());
$random=md5(rand(99,999));
$sl="insert into webtm_user values(NULL, '{$_POST['hoten']}', '{$_POST['diachi']}', '0123456789', '{$_POST['username']}', '{$_POST['pass']}', '{$_POST['email']}', '$ngaydk', 0, NULL, NULL, 0, '$random', 0)";
if(mysqli_query($link,$sl))
{
echo "Đăng ký thành công!";
include("gmail.php");
}
else echo $sl;
}
?>

//active.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_GET['key']))
{
include("connect.php");
$key=$_GET['key'];
$sl="update webtm_user set Active=1, RandomKey='' where RandomKey='$key'";
if(mysqli_query($link,$sl))
echo "Tài khoản đã được kích hoạt thành công!.......";
else echo $sl;
}
?>
</body>
</html>

//gmail.php

<?php
/**
 * This example shows settings to use when sending via Google's Gmail servers.
 */

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');

require 'PHPMailer-master/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';

$mail->Port = 465; //465

$mail->SMTPSecure = 'ssl'; //ssl

$mail->SMTPAuth = true;

$mail->Username = "";

$mail->Password = "";

$mail->setFrom('', 'Nguyen Van Teo');

$mail->addReplyTo('', 'Nguyen Van Teo');

$mail->addAddress($_POST['email'], $_POST['hoten']);

$mail->Subject = 'Kích hoạt tài khoản!';

$mail->msgHTML("Xin chào bạn! Click vào <a href='http://localhost:8080/tintuc/dangky/active.php?key=$random'>đây</a> để kích hoạt tài khoản");
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

Comments

Popular posts from this blog

PHP#33MySQL#29 - Đếm lượt truy cập (KẾT THÚC KHÓA HỌC)

//hitcounter.php <?php session_start();  ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php  include("../connect.php"); //cập nhật số luowhtj truy cập: $sl="update counter set cnt=cnt+1"; mysqli_query($link,$sl); //Lấy dữ liệu số lượt truy cập để hiển thị ra web: $sl2="select * from counter"; $kq=mysqli_query($link,$sl2); $d=mysqli_fetch_array($kq); //Định dạng: $chuoi=str_pad($d['cnt'],6,"0",STR_PAD_LEFT); $luottrycap=""; for($i=0;$i<strlen($chuoi);$i++) { $tam=substr($chuoi,$i,1); $luottrycap.="<img src='images/$tam.png'/>"; } /*-Khi user truy cập vào website: +lần đầu tuy cập: Lưu thông tin của user lên csdl +Sau lần đầu tiên: cập nhtaaj lastvisit - Xóa các dòng dữ liệu quá 1 phút (Quy ước thời gian để khẳng định online hay offline: 1 phút) - Thống kê số liệu người dùng o...

Bài 2 - SOME OTHER TIME - Vào dịp khác

PHP#6 - MySQL#2 - Thêm, Sửa, Xóa trong SQL, tìm kiếm

  1. Tạo bảng khachhang với các thuộc tính sau: 2. Dùng lệnh SQL : - Thêm dữ liệu cho bảng khachhang: => INSERT INTO khachhang VALUES(1, "nguyen VAN thanh", "aa", "123", "Q1", "a") INSERT INTO khachhang VALUES(2, "NGUYEN thi Linh", "bb", "123456", "q1", "123456", "b") INSERT INTO khachhang VALUES(3, "Nguyen Van Teo", "teovn", "123456", "aa", "88", "lo@a.com") Sửa Địa chỉ của user aa thành Q10 =>UPDATE khachhang SET DiaChi="Q10" WHERE UserName="aa" Sửa số điện thoại của user teonv thanh 093445212 =>UPDATE khachhang SET DienThoai="093445212" WHERE UserName="teovn" Xóa tất cả user nào có email la b =>DELETE FROM khachhang WHERE Email="b" //KẾT QUẢ //Bài tiếp theo: Câu lệnh Select đơn giản Chỉ có phần select from. Có thể có thêm where. Ví dụ: 1.   SELECT ...