-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlienhe.php
More file actions
72 lines (71 loc) · 3.04 KB
/
Copy pathlienhe.php
File metadata and controls
72 lines (71 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">
<?php
function goimail($to, $to_name, $subject, $noidungthu){
require "PHPMailer-master/src/PHPMailer.php"; //nhúng thư viện vào để dùng, sửa lại đường dẫn cho đúng nếu bạn lưu vào chỗ khác
require "PHPMailer-master/src/SMTP.php"; //nhúng thư viện vào để dùng
require 'PHPMailer-master/src/Exception.php'; //nhúng thư viện vào để dùng
$mail = new PHPMailer\PHPMailer\PHPMailer(true); //true: enables exceptions
try {
$mail->SMTPDebug = 2; // 0,1,2: chế độ debug. khi mọi cấu hình đều tớt thì chỉnh lại 0 nhé
$mail->isSMTP();
$mail->CharSet = "utf-8";
$mail->Host = 'smtp.gmail.com'; //SMTP servers
$mail->SMTPAuth = true; // Enable authentication
$nguoigui = 'emailCủaBạn@gmail.com';
$matkhau = 'mật khẩu';
$tennguoigui = 'Nhập tên người gửi';
$mail->Username = $nguoigui; // SMTP username
$mail->Password = $matkhau; // SMTP password
$mail->SMTPSecure = 'ssl'; // encryption TLS/SSL
$mail->Port = 465; // port to connect to
$mail->setFrom($nguoigui, $tennguoigui );
$mail->addAddress($to, $to_name); //mail và tên người nhận
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $noidungthu;
$mail->smtpConnect( array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
)
));
$mail->send();
echo 'Đã gửi mail xong';
} catch (Exception $e) {
echo 'Mail không gửi được. Lỗi: ', $mail->ErrorInfo;
}
}
if (isset($_POST['guilienhe'])==true){
$hoten = trim(strip_tags($_POST['hoten']));
$email = trim(strip_tags($_POST['email']));
$noidung = trim(strip_tags($_POST['noidung']));
$to = 'emailCủa@QWuảnTriWebsite';
$to_name="Họ tên người quản trị";
$subject ='Thư liên hệ từ khách hàng';
$noidungthu = "<p>
Họ tên khách hàng: $hoten<br>
Email khách hàng: $email<br>
Nội dung liên hệ : <br>
$noidung
</p>";
goimail($to, $to_name, $subject, $noidungthu);
}
?>
<form method="post" class="col-8 m-auto">
<h4>LIÊN HỆ QUẢN TRỊ</h4>
<p class="mb-3">
<span>Họ tên của bạn</span>
<input class="form-control" name="hoten">
</p>
<p class="mb-3">
<span>Email của bạn</span>
<input class="form-control" name="email">
</p>
<p class="mb-3">
<textarea class="form-control" name="noidung" rows="5"></textarea>
</p>
<p class="mb-3">
<button type="submit" name="guilienhe" class="btn btn-success">Gửi liên hệ</button>
</p>
</form>