-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
93 lines (74 loc) · 2.68 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
<!DOCTYPE html>
<head>
<title>CONTACT US</title>
<link rel="stylesheet" href="css/contact.css">
</head>
<body>
<div class="main">
<div class="header">
<h1>CONTACT US</h1><hr>
</div>
<div class="form">
<form method="post" action="">
<label for="name">Name:</label>
<input type="text" name="name" id="name" required>
<label for="email">Email:</label>
<input type="email" name="email" id="email" required>
<label for="subject">Subject:</label>
<input type="text" name="subject" id="subject" required>
<label for="message">Message:</label>
<textarea name="message" id="message" rows="5" required></textarea>
<button type="submit" name="submit" id="submit">SUBMIT</button>
</form>
</div>
</div>
</body>
</html>
<?php
// Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
// Load Composer's autoloader
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$connection=mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,'swapshop_next');
if($connection-> connect_error)
{
die("connection failed:".$connection-> connect_error);
}
if(isset($_POST['submit']))
{
// Get the form data
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Create a new PHPMailer instance
$mail = new PHPMailer(true);
try {
// Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'swapshop.next@gmail.com'; // SMTP username
$mail->Password = 'pejvmsudgytfcqhs'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
// Recipients
$mail->setFrom($email, $name);
$mail->addAddress( $email,$name); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>