-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontactform.php
More file actions
176 lines (134 loc) · 6.44 KB
/
Copy pathcontactform.php
File metadata and controls
176 lines (134 loc) · 6.44 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
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
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Content-Type: application/json");
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
$errors = array();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require 'vendor/autoload.php';
\Dotenv\Dotenv::createImmutable(__DIR__)->load();
// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
$sender = 'ayomide@repotecc.com';
$senderName = 'Repotecc';
$recipient = 'info@repotecc.com';
// Replace smtp_username with your Amazon SES SMTP user name.
$usernameSmtp = $_ENV['USERNAME_SMTP'];
// // Replace smtp_password with your Amazon SES SMTP password.
$passwordSmtp = $_ENV['PASSWORD_SMTP'];
// Specify a configuration set. If you do not want to use a configuration
// set, comment or remove the next line.
$configurationSet = 'ConfigSet';
// If you're using Amazon SES in a region other than US West (Oregon),
// replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP
// endpoint in the appropriate region.
$host = 'ssl://email-smtp.eu-west-2.amazonaws.com';
$port = 443;
$bodyText = "Email Test\r\nThis email was sent through the
Amazon SES SMTP interface using the PHPMailer class.";
// The HTML-formatted body of the email
$bodyHtml = '<h1>Email Test</h1>
<p>This email was sent through the
<a href="https://aws.amazon.com/ses">Amazon SES</a> SMTP
interface using the <a href="https://github.com/PHPMailer/PHPMailer">
PHPMailer</a> class.</p>';
if ($_SERVER['REQUEST_METHOD'] === "POST") {
if (empty($_POST['contact_email'])) {
$errors[] = 'Email is empty';
} else {
//$email = $_POST['email'];
$first_name = $_POST["contact_fname"];
$last_name = $_POST["contact_lname"];
$contact_phone = $_POST["contact_phone"];
$email = $_POST["contact_email"];
$contact_title = $_POST["contact_title"];
$contact_message = $_POST["contact_message"];
// validating the email
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Invalid email';
}
}
if (empty($_POST['contact_message'])) {
$errors[] = 'Message is empty';
} else {
$message = $_POST['contact_message'];
}
if (empty($errors)) {
$date = date('j, F Y h:i A');
$bodyHtml = " <html>
<head>
<title>
$email is contacting you
</title>
</head>
<body style=\"background-color:#fafafa;\">
<div style=\"padding:20px;\">
Date: <span style=\"color:#888\">$date</span>
<br> FullName: <span style=\"color:#888\">$first_name</span>
<span style=\"color:#888\">$last_name</span>
<br> Email: <span style=\"color:#888\">$email</span>
<br> Contact Phone: <span style=\"color:#888\">$contact_phone</span>
<br> Message Title: <span style=\"color:#888\">$contact_title</span>
<br> Message <span style=\"color:#888\">$contact_message</span>
</div>
</body>
</html>";
$headers = 'From: Contact Form <info@repotecc.com>' . "\r\n" .
"Reply-To: $email" . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=iso-8859-1\r\n";
$to = 'info@repotecc.com';
$subject = 'Contact Us';
$mail = new PHPMailer(true);
try {
// Specify the SMTP settings.
$mail->isSMTP(true);
$mail->setFrom($sender, $senderName);
$mail->Username = $usernameSmtp;
$mail->Password = $passwordSmtp;
$mail->Host = $host;
$mail->Port = $port;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
// $mail->addCustomHeader('X-SES-CONFIGURATION-SET', $configurationSet);
// Specify the message recipients.
$mail->addAddress($recipient);
// You can also add CC, BCC, and additional To recipients here.
// Specify the content of the message.
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $bodyHtml;
$mail->AltBody = $bodyText;
$mail->Send();
// echo "Email sent!" , PHP_EOL;
$sent = true;
} catch (phpmailerException $e) {
echo "An error occurred. {$e->errorMessage()}", PHP_EOL; //Catch errors from PHPMailer.
} catch (Exception $e) {
echo "Email not sent. {$mail->ErrorInfo}", PHP_EOL; //Catch errors from Amazon SES.
}
?>
<?php
// if (mail(
// $to, $subject, $emailBody, $headers)) {
// $sent = true;
// }
}
}
?>
<?php if (!empty($errors)) : ?>
{
"status": "fail",
"error": <?php echo json_encode($errors) ?>
}
<?php endif; ?>
<?php
if (isset($sent) && $sent === true) : ?> {
"status": "success",
"message": "Your data was successfully submitted"
}
<?php endif; ?>