Add files

This commit is contained in:
Asif Bacchus 2020-07-28 09:29:51 -06:00
commit 0ade3fed4d
9 changed files with 6603 additions and 0 deletions

3
.vscode/numbered-bookmarks.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"bookmarks": []
}

13
config.php Normal file
View File

@ -0,0 +1,13 @@
<?php
/*
--- SMTP server settings ---
This is the only file that should be edited!
*/
$SMTP = [
'timeout' => '',
'hostname' => '',
'username' => '',
'password' => ''
];
?>

130
index.php Normal file
View File

@ -0,0 +1,130 @@
<?php
// show all errors and set global timeout
include_once('php/00_showErrors.include.php');
// include SMTP configuration and mailer function
include_once('config.php');
include_once('php/PHPMailer/mailer.php');
function missingConfig($missingParam){
echo '<h1>Configuration Error</h1>';
echo '<p>Please re-check <span style="font-weight: bold">config.php</span>. It appears you forgot to provide a value for <span style="font-weight: bold">' . $missingParam . '</span>.</p>';
echo '<p>Unable to continue until configuration error has been resolved.</p>';
die();
}
// global variables
$output = $usePort = $useEncryption = $recipient = $replyTo = NULL;
// check configuration for missing entries
if (!$SMTP['timeout']) $SMTP['timeout'] = 15;
if (!$SMTP['hostname']) missingConfig('hostname');
if (!$SMTP['username']) missingConfig('username');
if (!$SMTP['password']) missingConfig('password');
// process POST request if made
if (isset($_POST) && !empty($_POST)){
// retain settings
if (!empty($_POST['port'])){
$usePort = $_POST['port'];
} else{
$output .= '<< no port selected >><br>';
}
if (!empty($_POST['encryption'])){
$useEncryption = $_POST['encryption'];
} else{
$output .= '<< no encryption selected >><br>';
}
if (!empty($_POST['recipient'])){
$recipient = filter_var($_POST['recipient'], FILTER_VALIDATE_EMAIL) ? $_POST['recipient'] : $output .= '<< no recipient address specified >><br>';
} else{
$output .= '<< no recipient address specified >><br>';
}
if (!empty($_POST['replyTo'])){
$replyTo = filter_var($_POST['replyTo'], FILTER_VALIDATE_EMAIL) ? $_POST['replyTo'] : $output .= '<< no reply address specified >><br>';
} else{
$output .= '<< no reply address specified >><br>';
}
// send email IFF no NULL fields
if ($usePort && $useEncryption && $recipient && $replyTo){
$body = 'This is a test message from the AB-GROUP PHP Email Port Tester PHP script. You may ignore this message.';
$subject = 'Test message from AB-GROUP Port Test Script';
$mailResult = sendEmail($SMTP['timeout'], $SMTP['hostname'], $usePort, $useEncryption, $SMTP['username'], $SMTP['password'], $recipient, $replyTo, $body, $subject);
$output .= $mailResult['debug'];
}
} else{
$output = '<< click the TEST button to start testing >>';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Port Test</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Email Port Test</h1>
<p class="notice">*** Remember to remove this page when you are finished testing! This page has NO protections against being used for SPAM or being otherwise abused! ***</p>
<p>Fill in the form options below and click the 'TEST' button. Diagnostic data will be displayed whether or not the test email was successfully relayed.</p>
<form action="index.php" method="post" class="form">
<div class="options">
<div class="portSelect">
<p>port:</p>
<label for="port25" class="radioLabel">
<input type="radio" name="port" id="port25" class="btn_radio" value=25 <?php echo (isset($usePort) && $usePort === '25') ? 'checked' : NULL;?>>
SMTP (port 25)
</label>
<label for="port465" class="radioLabel">
<input type="radio" name="port" id="port465" class="btn_radio" value=465 <?php echo (isset($usePort) && $usePort === '465') ? 'checked' : NULL;?>>
SMTP/S (port 465)
</label>
<label for="port587" class="radioLabel">
<input type="radio" name="port" id="port587" class="btn_radio" value=587 <?php echo (isset($usePort) && $usePort === '587') ? 'checked' : NULL;?>>
SUBMISSION (port 587)
</label>
<label for="port2525" class="radioLabel">
<input type="radio" name="port" id="port2525" class="btn_radio" value=2525 <?php echo (isset($usePort) && $usePort === '2525') ? 'checked' : NULL;?>>
Alternate SMTP 2525
</label>
</div>
<div class="encryptionSelect">
<p>encryption:</p>
<label for="noEnc" class="radioLabel">
<input type="radio" name="encryption" id="noEnc" class="btn_radio" value="none" <?php echo (isset($useEncryption) && $useEncryption === 'none') ? 'checked' : NULL;?>>
NONE
</label>
<label for="ssl" class="radioLabel">
<input type="radio" name="encryption" id="ssl" class="btn_radio" value="ssl" <?php echo (isset($useEncryption) && $useEncryption === 'ssl') ? 'checked' : NULL;?>>
SSL
</label>
<label for="starttls" class="radioLabel">
<input type="radio" name="encryption" id="starttls" class="btn_radio" value="starttls" <?php echo (isset($useEncryption) && $useEncryption === 'starttls') ? 'checked' : NULL;?>>
STARTTLS
</label>
</div>
</div>
<div class="addresses">
<label for="recipient" class="textLabel">
<span class="bold">Recipient:</span>
<input type="email" name="recipient" id="recipient" class="textbox" value="<?php echo (isset($recipient)) ? $recipient : ''; ?>">
</label>
<label for="replyTo" class="textLabel">
<span class="bold">Reply To:</span>
<input type="email" name="replyTo" id="replyTo" class="textbox" value="<?php echo (isset($replyTo)) ? $replyTo : ''; ?>">
</label>
</div>
<div class="buttons">
<button type="submit" class="btn">TEST</button>
<button type="reset" class="btn">CLEAR</button>
</div>
</form>
<h2>Diagnostic Output:</h2>
<div class="diagOutput">
<!-- phpmailer output here-->
<?php echo $output; ?>
</div>
</body>
</html>

View File

@ -0,0 +1,5 @@
<?php
// display all errors while testing
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

View File

@ -0,0 +1,39 @@
<?php
/**
* PHPMailer Exception class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer exception handler.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class Exception extends \Exception
{
/**
* Prettify error message output.
*
* @return string
*/
public function errorMessage()
{
return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
}
}

4834
php/PHPMailer/PHPMailer.php Normal file

File diff suppressed because it is too large Load Diff

1371
php/PHPMailer/SMTP.php Normal file

File diff suppressed because it is too large Load Diff

75
php/PHPMailer/mailer.php Normal file
View File

@ -0,0 +1,75 @@
<?php
// import PHPMailer
set_include_path (__DIR__);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer.php';
require 'SMTP.php';
require 'Exception.php';
// global var for debug logging
$debugOutput = '';
function sendEmail($timeout, $hostname, $usePort, $useEncryption, $username, $password, $recipient, $replyTo, $body, $subject) {
try {
// instantiate PHPMailer instance (true = enable exceptions)
$result = [];
$mail = new PHPMailer(true);
// server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // enable verbose output
$mail->Debugoutput = function($str){
$GLOBALS['debugOutput'] .= "$str<br>";
};
$mail->Timeout = $timeout;
$mail->isSMTP();
$mail->Host = $hostname;
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
// encryption setting
if ($useEncryption === 'ssl'){
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
} elseif ($useEncryption === 'starttls'){
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
}
$mail->Port = $usePort;
// recipients
$mail->setFrom($replyTo);
$mail->addAddress($recipient);
$mail->addReplyTo($replyTo);
// content
$mail->Subject = $subject;
//$mail->msgHTML($body);
//$mail->isHtml(true);
$mail->isHtml(false);
$mail->Body = $body;
// send message
if (!$mail->send()) {
$result = [
'result' => false,
'message' => $mail->ErrorInfo,
'debug' => $GLOBALS['debugOutput']
];
} else {
$result = [
'result' => true,
'debug' => $GLOBALS['debugOutput']
];
}
} catch (Exception $e) {
$result = [
'result' => false,
'errorMessage' => $e->getMessage(),
'debug' => $GLOBALS['debugOutput']
];
} finally {
return $result;
}
}
?>

133
styles.css Normal file
View File

@ -0,0 +1,133 @@
* {
box-sizing: border-box;
}
:root body {
font-size: 16px;
line-height: 22px;
margin: 0;
padding: 16px 32px;
}
h1 {
font-size: 26px;
font-weight: bold;
}
h2 {
font-size: 20px;
font-weight: bold;
}
.bold {
font-weight: bold;
}
.notice {
font-weight: bold;
color: red;
text-align: center;
line-height: 22px;
}
/* form styles */
.form {
align-items: center;
display: flex;
flex-direction: column;
margin: 32px auto;
}
.form > div {
margin: 4px 0;
padding: 4px;
width: 50%;
}
.form p {
font-weight: bold;
margin: 0 0 8px;
text-transform: capitalize;
}
.btn {
background-color: transparent;
border: 1px solid black;
font: inherit;
margin: 0 4px;
padding: 8px 32px;
transition: all 0.25s ease;
width: 25%;
}
.btn:hover,
.btn:focus {
background-color: black;
color: white;
}
.radioLabel,
.textLabel {
align-items: baseline;
display: flex;
}
.radioLabel {
margin-bottom: 8px;
}
.textbox {
border-bottom: 1px solid #ababab;
border-left: none;
border-right: none;
border-top: none;
flex: 1;
font: inherit;
margin-left: 8px;
outline: none;
}
.textLabel {
margin-bottom: 16px;
}
/* form: addresses section */
.addresses {
display: flex;
flex-direction: column;
padding: 16px 8px;
}
/* form: buttons section */
.buttons {
display: flex;
justify-content: center;
}
/* form: options section */
.options {
display: flex;
justify-content: space-evenly;
}
.encryptionSelect {
display: flex;
flex-direction: column;
justify-content: start;
}
.portSelect {
display: flex;
flex-direction: column;
}
/* phpmailer diagnostic output section */
.diagOutput {
border: 1px solid black;
height: 250px;
margin: 0 auto;
max-height: 250px;
overflow-y: auto;
padding: 8px;
width: 85%;
}