-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
110 lines (103 loc) · 6.22 KB
/
index.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['smtp'])) {
$smtp_server = ($_POST['smtp_server']);
$smtp_port = ($_POST['smtp_port']);
$smtp_encryption = ($_POST['smtp_encryption']);
$smtp_debug = ($_POST['smtp_debug']);
$smtp_username = ($_POST['smtp_username']);
$smtp_password = ($_POST['smtp_password']);
$email_from = ($_POST['email_from']);
$email_to = ($_POST['email_to']);
require 'lib/phpmailer/src/Exception.php';
require 'lib/phpmailer/src/PHPMailer.php';
require 'lib/phpmailer/src/SMTP.php';
$email = new PHPMailer;
$email->IsSMTP();
$email->Host = $smtp_server;
$email->Port = $smtp_port;
$email->SMTPAuth = true;
$email->SMTPDebug = $smtp_debug;
$email->SMTPSecure = $smtp_encryption;
$email->Username = $smtp_username;
$email->Password = $smtp_password;
$email->setFrom($email_from);
$email->addAddress($email_to);
$email->Subject = 'SMTP Test Email';
$email->Body = 'Hooray, your SMTP is working correctly!';
if ($email->send()) {
$message = '<div class="alert alert-success" role="alert">SMTP is working and email has been successfully sent!</div>';
} else {
$message = '<div class="alert alert-danger" role="alert">SMTP is not working and email has failed to send!<br>Error: ' . $email->ErrorInfo . '</div>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Harrison Ratcliffe">
<meta name="description" content="A simple tool to check your SMTP is working, built in PHP.">
<title>PHP SMTP Checker</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<main class="form-signin">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="pure-form pure-form-stacked">
<fieldset>
<legend>PHP SMTP Checker</legend>
<?php if(!empty($message)) { echo $message; } ?>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-first-name">SMTP Server:</label>
<input type="text" name="smtp_server" required placeholder="smtp.server.com" class="pure-u-23-24" value="<?php echo isset($_POST['smtp_server']) ? $_POST['smtp_server'] : ''; ?>" />
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-last-name">SMTP Port:</label>
<input type="number" name="smtp_port" required placeholder="465" class="pure-u-23-24" value="<?php echo isset($_POST['smtp_port']) ? $_POST['smtp_port'] : ''; ?>" />
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-state">Encryption</label>
<select name="smtp_encryption" require class="pure-input-1-2">
<option value="none" <?php echo (isset($_POST['smtp_encryption']) && $_POST['smtp_encryption'] == 'none') ? 'selected' : ''; ?>>None</option>
<option value="ssl" <?php echo (isset($_POST['smtp_encryption']) && $_POST['smtp_encryption'] == 'ssl') ? 'selected' : ''; ?>>SSL</option>
<option value="tls" <?php echo (isset($_POST['smtp_encryption']) && $_POST['smtp_encryption'] == 'tls') ? 'selected' : ''; ?>>TLS</option>
</select>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-state">Debug mode</label>
<select name="smtp_debug" require class="pure-input-1-2">
<option value="0" <?php echo (isset($_POST['smtp_debug']) && $_POST['smtp_debug'] == '0') ? 'selected' : ''; ?>>0</option>
<option value="1" <?php echo (isset($_POST['smtp_debug']) && $_POST['smtp_debug'] == '1') ? 'selected' : ''; ?>>1</option>
<option value="2" <?php echo (isset($_POST['smtp_debug']) && $_POST['smtp_debug'] == '2') ? 'selected' : ''; ?>>2</option>
<option value="3" <?php echo (isset($_POST['smtp_debug']) && $_POST['smtp_debug'] == '3') ? 'selected' : ''; ?>>3</option>
<option value="4" <?php echo (isset($_POST['smtp_debug']) && $_POST['smtp_debug'] == '4') ? 'selected' : ''; ?>>4</option>
</select>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-email">SMTP Username:</label>
<input type="text" name="smtp_username" required class="pure-u-23-24" value="<?php echo isset($_POST['smtp_username']) ? $_POST['smtp_username'] : ''; ?>" />
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-city">SMTP Password:</label>
<input type="password" name="smtp_password" required class="pure-u-23-24" />
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-city">Email from:</label>
<input type="email" name="email_from" required class="pure-u-23-24" value="<?php echo isset($_POST['email_from']) ? $_POST['email_from'] : ''; ?>" />
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="multi-city">Email to:</label>
<input type="email" name="email_to" required class="pure-u-23-24" value="<?php echo isset($_POST['email_to']) ? $_POST['email_to'] : ''; ?>" />
</div>
</div>
<button type="submit" name="smtp" class="pure-button pure-button-primary">Submit</button>
</fieldset>
</form>
</main>
</body>
</html>