-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
88 lines (62 loc) · 2.93 KB
/
Copy pathcontact.php
File metadata and controls
88 lines (62 loc) · 2.93 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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
/*Run locally
- navigate to where composer installed the PHPMailer Folder and add the path.
require 'C:\location\composer\vendor\autoload.php';*/
/*run on server*/
require '/home/username/PHPMailerTest/src/Exception.php'; //replace username with yours
require '/home/username/PHPMailerTest/src/PHPMailer.php'; // `` `` ``
require '/home/username/PHPMailerTest/src/SMTP.php'; // `` `` ``
//get variables
$name = ""; //value recieved from contact form
$subject = ""; //
$email = ""; //
$message = ""; //
$mailTo = ""; //input the email address for recieveing messages from contact form
//some validation
if(isset($_POST['name'])) {
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
}
if(isset($_POST['email'])) {
$email = str_replace(array("\r", "\n", "%0a", "%0d"), '', $_POST['email']);
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
}
if(isset($_POST['subject'])) {
$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
}
if(isset($_POST['message'])) {
$message = htmlspecialchars($_POST['message']);
}
/* Create a new PHPMailer object. Passing TRUE to the constructor enables exceptions. */
$mail = new PHPMailer(TRUE);
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = ''; // 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 = ; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom($email,$name);
$mail->addAddress($mailTo); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
//confirmation
/*echo 'Message has been sent'; <== debugging */
header("Location: https://luckyndlovu.ltechdev.co.za/thankyou.php"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
} catch (Exception $e) {
/*echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; <== debugging */
header("Location: https://luckyndlovu.ltechdev.co.za/ohno.php"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
}
?>