-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsentweb.php
More file actions
90 lines (80 loc) · 4.19 KB
/
sentweb.php
File metadata and controls
90 lines (80 loc) · 4.19 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
session_start();
include('server.php');
$errors = array();
$noterrors = array();
if(isset($_POST['submit'])){
$email = $_POST['emails'];
$name = $_POST['names'];
$phone = $_POST['phones'];
$message = $_POST['message'];
if(empty($email)&&empty($name)&&empty($phone)&&empty($message)){
array_push($errors, "กรุณากรอกข้อมูลเพื่อส่งอีเมล");
$_SESSION['error'] = "กรุณากรอกข้อมูลเพื่อส่งอีเมล";
header("location: contact.php");
}
else if(empty($email)){
array_push($errors, "กรุณากรอกอีเมล");
$_SESSION['error'] = "กรุณากรอกอีเมล";
header("location: contact.php");
}
else if(empty($name)){
array_push($errors, "กรุณากรอกชื่อ");
$_SESSION['error'] = "กรุณากรอกชื่อ";
header("location: contact.php");
}
else if(empty($phone)){
array_push($errors, "กรุณากรอกเบอร์");
$_SESSION['error'] = "กรุณากรอกเบอร์";
header("location: contact.php");
}
else if(empty($message)){
array_push($errors, "กรุณากรอกข้อความ");
$_SESSION['error'] = "กรุณากรอกข้อความ";
header("location: contact.php");
}
else{
require("phpmailer/class.phpmailer.php"); // path to the PHPMailer class.
$fm = "beebacorporation@gmail.com"; // *** ต้องใช้อีเมล์ @gmail.com เท่านั้น ***
$to = $email; // อีเมล์ที่ใช้รับข้อมูลจากแบบฟอร์ม
$custemail = $_POST['emails']; // อีเมล์ของผู้ติดต่อที่กรอกผ่านแบบฟอร์ม
$mail = new PHPMailer();
$mail->CharSet = "utf-8";
/* ------------------------------------------------------------------------------------------------------------- */
/* ตั้งค่าการส่งอีเมล์ โดยใช้ SMTP ของ Gmail */
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "beebacorporation@gmail.com"; // Gmail Email username
$mail->Password = "mistersigz"; // App Password not Gmail password
$mail->Subject = "แบบฟรอมจากคุณ $name";
/* ------------------------------------------------------------------------------------------------------------- */
$mail->setFrom($fm, $to);
$mail->AddAddress($fm);
$mail->AddReplyTo($fm);
$mail->isHTML(true);
$mail->Body = "
ชื่อ : $name <br>
อีเมล : $email<br>
เบอร์ : $phone<br>
เขียนว่า :<br>
$message
";
$mail->WordWrap = 50;
if(!$mail->Send()) {
array_push($errors, "ส่งอีเมลไม่สำเร็จ");
$_SESSION['error'] = "ส่งอีเมลไม่สำเร็จ";
header("location: home.php");
exit;
}
else {
array_push($noterrors, "ส่งอีเมลสำเร็จ");
$_SESSION['noterror'] = "ส่งอีเมลสำเร็จ";
header("location: home.php");
}}
}
?>