-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.php
56 lines (41 loc) · 1.87 KB
/
handler.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'php/PHPMailer-5.2.28/src/Exception.php';
require 'php/PHPMailer-5.2.28/src/PHPMailer.php';
require 'php/PHPMailer-5.2.28/src/SMTP.php';
$mail = new PHPMailer(true);
$mail_subject = 'Subject';
$mail_to_email = 'ianmwitumi@gmail.com'; // your email
$mail_to_name = 'Webmaster';
try {
$mail_from_email = isset( $_POST['email'] ) ? $_POST['email'] : '';
$mail_from_name = isset( $_POST['name'] ) ? $_POST['name'] : '';
$mail_category = isset( $_POST['category'] ) ? $_POST['category'] : '';
$mail_message = isset( $_POST['message'] ) ? $_POST['message'] : '';
// Server settings
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.***.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '***'; // SMTP username
$mail->Password = '***'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$mail->setFrom($mail_to_email, $mail_to_name); // Your email
$mail->addAddress($mail_from_email, $mail_from_name); // Add a recipient
for($ct=0; $ct<count($_FILES['file_attach']['tmp_name']); $ct++) {
$mail->AddAttachment($_FILES['file_attach']['tmp_name'][$ct], $_FILES['file_attach']['name'][$ct]);
}
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $mail_subject;
$mail->Body = '
<strong>Category:</strong> ' . $mail_category . '<br>
<strong>Name:</strong> ' . $mail_from_name . '<br>
<strong>Email:</strong> ' . $mail_from_email . '<br>
<strong>Message:</strong> ' . $mail_message;
$mail->Send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}