-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailer.php
More file actions
140 lines (117 loc) · 5.73 KB
/
emailer.php
File metadata and controls
140 lines (117 loc) · 5.73 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
<html>
<head>
<script src="jquery-3.3.1.min.js"></script>
<script src="checkall.js"></script>
</head>
<P>
<body>
<H3>CE Plus Test Files for end user device checks
</H3>
<p>
<!--
This is a script built to assist with end user device checks for Cyber Essentials Plus.
The use is hopefully fairly obvious - Enter an email address, select files (or not), and send.
This script requires PHP > 5.5, and also the PHPMailer library to be installed in a reference path.
PHPLibrary is available from https://github.com/PHPMailer/PHPMailer.
Please update the Server Settings section with your required email settings.
-->
<form method ="post" action="emailer.php" enctype="multipart/form-data">
Target User Email Address:
<?php
if (isset($_POST['Email'])){
$address = $_POST['Email'];
echo "<input name='Email' type='text' id='Email' size='66' value='$address' />";
} else {
echo "<input name='Email' type='text' id='Email' size='66' />";
}
?>
<p>
Please choose attachments to send. if no attachments are chosen a test email will be sent :</br>
<?php
$files = scandir("files");
foreach ($files as $file) {
if ($file != "." AND $file != ".."){
echo "<input type='checkbox' class='child' name=\"attachments[]\" value='$file' />$file<br>";
}
}
?>
<br>
<input type="checkbox" class="checkall" label="check all" />check all<br>
<input type="submit" value="Send selected files" onclick=return confirm('SEND selected files?'); />
</form>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
$err=0;
$Email = $_POST['Email'];
#$Filename = $_REQUEST['Filename'];
if (empty($Email)) {
if ($err==0) echo("<html> <h1>Error</h1><p>"); $err=1;
echo("<p>No email address supplied!<p>"); }
if (preg_match('/[^a-z0-9.@-_]/i', $Email)){
print "Invalid characters found in email address<p>";
$err=1; }
if ($err==1) echo("Please enter the target address and try again. </p> </body> </html>");
if(isset($_POST['attachments'])){
$myboxes = $_POST['attachments'];
}
//Server settings
$mail = new PHPMailer(true);
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = '127.0.0.1'; // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Enable SMTP authentication
#$mail->Username = 'user@example.com'; // SMTP username
#$mail->Password = 'secret'; // SMTP password
#$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('security@email.com', 'From Name');
$mail->addAddress($Email); // Add a recipient
$mail->addReplyTo('security@email.com', 'Reply Name');
#$mail->addCC('cc@example.com');
#$mail->addBCC('bcc@example.com');
if(empty($myboxes)){
echo("Sending test email to " . $Email . "<br>");
try {
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Cyber Essentials Plus test email';
$mail->Body = 'This email has been sent with no attachments to ensure email delivery is functioning';
$mail->AltBody = 'This email has been sent with no attachments to ensure email delivery is functioning';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
} else {
$i = count($myboxes);
echo("You selected $i box(es): <br>");
for ($j = 0; $j < $i; $j++){
try {
$attach = $myboxes[$j];
echo 'Sending email ' . ($j+1) . '/' . $i . ' with attachment ' . $attach . ' to ' . $Email . '<br>';
//Attachments
$mail->clearAttachments();
$mail->addAttachment('files/' . $attach); // Add attachments
#$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Cyber Essentials Plus with attachment ' . ($j+1) . '/' . $i . ' - ' . $attach;
$mail->Body = 'Sent with attachment '.$attach;
$mail->AltBody = 'Sent with attachment '.$attach;
$mail->send();
echo 'Message has been sent <br>';
}
catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
echo 'Message sending complete';
}
}
}
?>
</body>