-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathcontact.php
231 lines (178 loc) · 7.98 KB
/
contact.php
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
session_start();
define('TITLE',"Contact Us | KLiK");
include 'includes/HTML-head.php';
include 'includes/email-server.php';
?>
<link rel="stylesheet" type="text/css" href="css/contact-util.css">
<link rel="stylesheet" type="text/css" href="css/contact-main.css">
</head>
<body>
<?php
if(isset($_SESSION['userId']))
{
include 'includes/navbar.php';
}
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
// check for header injection
function has_header_injection($str){
return preg_match('/[\r\n]/',$str);
}
if (isset($_POST['contact_submit'])){
if(!isset($_SESSION['userId']))
{
$email = trim($_POST['email']);
$name = trim($_POST['first-name']).' '.trim($_POST['last-name']);
}
else
{
$email = trim($_SESSION['emailUsers']);
$name = 'User: '.$_SESSION['userUid'];
}
$msg = $_POST['message'];
if (has_header_injection($name) || has_header_injection($email)){
die();
}
if (! $name || ! $email || ! $msg){
echo '<h4 class="error">All Fields Required.</h4>'
. '<a href="contact.php" class="button block">go back and try again</a>';
exit;
}
$to = $email;
$subject = "$name sent you a message via your contact form";
$message = "<strong>Name:</strong> $name<br>"
. "<strong>Email:</strong> <i>$email</i><br><br>"
. "<strong>Message:</strong><br><br>$msg";
if (isset($_POST['subscribe']))
{
$message .= "<br><br><br>"
. "<strong>IMPORTANT:</strong> Please add <i>$email</i> "
. "to your mailing list.<br>";
}
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = $SMTPuser;
$mail->Password = $SMTPpwd;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
//Recipients
$mail->setFrom($to, $SMTPtitle);
$mail->addAddress($SMTPuser, $SMTPtitle);
//Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
}
catch (Exception $e) {
echo '<h4 class="error">Message could not be sent. Mailer Error: '. $mail->ErrorInfo
.'</h4>';
}
}
?>
<div class="container-contact100">
<div class="wrap-contact100">
<form class="contact100-form validate-form" method="post" action="">
<span class="contact100-form-title">
Send Us A Message
</span>
<?php
if(!isset($_SESSION['userId']))
{
?>
<label class="label-input100" for="first-name">Tell us your name *</label>
<div class="wrap-input100 rs1-wrap-input100 validate-input" data-validate="Type first name">
<input id="first-name" class="input100" type="text" name="first-name" placeholder="First name">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 rs2-wrap-input100 validate-input" data-validate="Type last name">
<input class="input100" type="text" name="last-name" placeholder="Last name">
<span class="focus-input100"></span>
</div>
<label class="label-input100" for="email">Enter your email *</label>
<div class="wrap-input100 validate-input" data-validate = "Valid email is required: [email protected]">
<input id="email" class="input100" type="text" name="email" placeholder="Eg. [email protected]">
<span class="focus-input100"></span>
</div>
<?php
}
?>
<div class="checkbox-animated my-4">
<input id="checkbox_animated_1" type="checkbox" name="subscribe" value="subscribe">
<label for="checkbox_animated_1">
<span class="check"></span>
<span class="box"></span>
Subscribe for Updates
</label>
</div>
<label class="label-input100" for="message">Message *</label>
<div class="wrap-input100 validate-input" data-validate = "Message is required">
<textarea id="message" class="input100" name="message" rows="8"
placeholder="Write us a message"></textarea>
<span class="focus-input100"></span>
</div>
<div class="container-contact100-form-btn">
<input type="submit" class="contact100-form-btn"
name="contact_submit" value="Send Message">
</div>
</form>
<div class="contact100-more flex-col-c-m" style="background-image: url('img/contact.jpg');">
<div class="flex-w size1 p-b-47">
<div class="txt1 p-r-25">
<span class="lnr lnr-map-marker"></span>
</div>
<div class="flex-col size2">
<span class="txt1 p-b-20">
About Us
</span>
<span class="txt2">
University Students stumbling onto new ambitions<br>
NUST, Islamabad Pakistan
</span>
</div>
</div>
<div class="dis-flex size1 p-b-47">
<div class="txt1 p-r-25">
<span class="lnr lnr-phone-handset"></span>
</div>
<div class="flex-col size2">
<span class="txt1 p-b-20">
Star Our Work
</span>
<span class="txt3">
github.com/msaad1999/KLiK--PHP-coded-Social-Media-Website
</span>
</div>
</div>
<div class="dis-flex size1 p-b-47">
<div class="txt1 p-r-25">
<span class="lnr lnr-envelope"></span>
</div>
<div class="flex-col size2">
<span class="txt1 p-b-20">
General Support
</span>
<span class="txt3">
</span>
</div>
</div>
<?php
if(!isset($_SESSION['userId']))
{
echo '<a class="contact100-form-btn" href="login.php">Login Page</a>';
}
?>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>
<script src="js/contact-main.js"></script>
<?php include 'includes/HTML-footer.php' ?>