Skip to content

Instantly share code, notes, and snippets.

@sam452
Created August 5, 2015 16:27
Show Gist options
  • Save sam452/4784ebde6c605340630b to your computer and use it in GitHub Desktop.
Save sam452/4784ebde6c605340630b to your computer and use it in GitHub Desktop.
simple test for email on server.
<?php
if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') {
date_default_timezone_set('Etc/UTC');
require './PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 1;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = $_POST['server'];
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = $_POST['port'];
//Set the encryption system to use - ssl (deprecated) or tls
if (strlen($_POST['encrypt'])) {
$mail->SMTPSecure = $_POST['encrypt'];
}
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->Username = $_POST['username'];
$mail->Password = $_POST['password'];
$mail->setFrom($_POST['username']);
$mail->addAddress($_POST['to']);
$mail->Subject = 'DOM Test';
$mail->msgHTML('This is a test!');
$mail->AltBody = 'This is a test!';
if (!$mail->send()) {
$msg = "Mailer Error: " . $mail->ErrorInfo;
} else {
$msg = "Message sent!";
}
}
?><!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>Email Test</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<body>
<div style="width:800px;margin:auto;">
<?php if (isset($msg) && strlen($msg)>0) {
echo '<div class="alert alert-info" role="alert">'.$msg.'</div>';
}?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Email test</h3>
</div>
<div class="panel-body">
<form method="POST">
<fieldset>
<div class="control-group">
<!-- Text input-->
<label class="control-label" for="input01">SMTP server</label>
<div class="controls">
<input type="text" placeholder="smtp.gmail.com" class="input-xlarge" name="server">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<!-- Text input-->
<label class="control-label" for="input01">Username</label>
<div class="controls">
<input type="text" placeholder="[email protected]" class="input-xlarge" name="username">
<p class="help-block"></p>
</div>
</div><div class="control-group">
<!-- Text input-->
<label class="control-label" for="input01">Password</label>
<div class="controls">
<input type="password" placeholder="" class="input-xlarge" name="password">
<p class="help-block"></p>
</div>
</div><div class="control-group">
<!-- Text input-->
<label class="control-label" for="input01">SMTP port</label>
<div class="controls">
<input type="text" placeholder="587" class="input-xlarge" name="port">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<!-- Select Basic -->
<label class="control-label">Use encrypted protocol</label>
<div class="controls">
<select class="input-xlarge" name="encrypt">
<option vlaue="tls">TLS</option>
<option value="ssl">SSL</option>
<option value="">NO</option></select>
</div>
</div>
<div class="control-group">
<!-- Text input-->
<label class="control-label" for="input01">To email</label>
<div class="controls">
<input type="text" placeholder="" class="input-xlarge" name="to">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<!-- Button -->
<div class="controls">
<button class="btn" type="submit">Test</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment