Adding PHP mail sender to the repo

This commit is contained in:
Filip 2019-08-01 14:24:11 +02:00
parent 4075a2ab7f
commit db9887058d
4 changed files with 138 additions and 0 deletions

71
index.html Normal file
View File

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PHP Mail Sender</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
div.half {
float: left;
width: 50%;
width: 48%;
margin: 0 1%;
}
@media screen and (max-width: 600px) {
div.half {
clear: both;
}
}
</style>
</head>
<body>
<form method="get" action="php-mail-sender.zip" method="get" target="_blank">
<button>Download script</button>
</form>
<div class="half">
<form action="mail-smtp.php" method="post">
<h1>PHP Mailer over SMTP server</h1>
<p>Server:</p>
<input type="text" name="server">
<p>Username:</p>
<input type="text" name="username">
<p>Password:</p>
<input type="password" name="password">
<p>Port:</p>
<input type="text" name="port">
<p>Encryption:</p>
<select name="encryption">
<option value="ssl">SSL</option>
<option value="tls">TLS</option>
<option value="none">No encryption</option>
</select>
<p>Email from:</p>
<input type="text" name="from-email">
<p>Email to:</p>
<input type="text" name="recipient-email">
<br>
<br>
<input type="submit" value="Send">
<br>
<br>
<button type="reset" value="Reset">Reset</button>
</form>
</div>
<div class="half">
<form action="mail.php" method="post">
<h1>PHP mailer</h1>
<p>Email from:</p>
<input type="text" name="from-email">
<p>Email to:</p>
<input type="text" name="recipient-email">
<br>
<br>
<input type="submit" value="Send">
<br>
<br>
<button type="reset" value="Reset">Reset</button>
<br>
</form>
</div>
</body>
</html>

41
mail-smtp.php Normal file
View File

@ -0,0 +1,41 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Include PHPMailer library files
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer;
// SMTP configuration
$mail->isSMTP();
$mail->Host = $_POST['server']; // Client's mail server
$mail->SMTPAuth = true;
$mail->Username = $_POST['username']; // Client's email username
$mail->Password = $_POST['password']; // Client's password
if ($_POST['encryption'] != "none") {
$mail->SMTPSecure = $_POST['encryption'];
}
$mail->Port = $_POST['port']; // SMTP Port
// Mail configuration
$mail->setFrom($_POST['from-email'], 'Tester'); // Email From field
// Recipient info
$mail->addAddress($_POST['recipient-email']); // Email To field
$mail->Subject = 'PHPMailer over SMTP Test'; // Email Subject field
$mail->Body = 'This email has been sent using PHPMailer (over SMTP) for test purposes.'; // Email Body field
// Send email report
if(!$mail->send()) {
echo '<span style="color: red;">Message could not be sent.</span><br>';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo '<span style="color: green;">Message has been sent.</span><br>';
echo 'Server: ' . $_POST['server'] . '<br>';
echo 'Port: ' . $_POST['port'] . '<br>';
echo 'Encryption: ' . $_POST['encryption'] . '<br>';
echo 'Username: ' . $_POST['username'];
}

26
mail.php Normal file
View File

@ -0,0 +1,26 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Include PHPMailer library files
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer;
// Mail configuration
$mail->setFrom($_POST['from-email'], 'Tester'); // Email From field
// Recipient info
$mail->addAddress($_POST['recipient-email']); // Email To field
$mail->Subject = 'PHPMailer Test'; // Email Subject field
$mail->Body = 'This email has been sent using PHPMailer for test purposes.'; // Email Body field
// Send email report
if(!$mail->send()){
echo '<span style="color: red;">Message could not be sent.</span><br>';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}else{
echo '<span style="color: green;">Message has been sent.</span>';
}

BIN
php-mail-sender.zip Normal file

Binary file not shown.