Created
July 24, 2013 21:37
-
-
Save Petah/6074805 to your computer and use it in GitHub Desktop.
Simple PHP email test script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Disclaimer: this script is for test purposes only, it is not intended to be secure. | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
if (isset($_POST['to']) && | |
isset($_POST['from']) && | |
isset($_POST['subject']) && | |
isset($_POST['message'])) { | |
$headers = 'From: ' . $_POST['from'] . PHP_EOL | |
. 'Reply-To: ' . $_POST['from'] . PHP_EOL | |
. 'X-Mailer: PHP/' . phpversion(); | |
if (mail($_POST['to'], $_POST['subject'], $_POST['message'], $headers)) { | |
echo 'Mail function returned success.'; | |
} else { | |
echo 'Mail function returned failure.'; | |
} | |
} | |
$version = phpversion(); | |
$date = date('Y-m-d H:i:s'); | |
$fullURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
$from = 'php@' . $_SERVER['SERVER_NAME']; | |
?> | |
<style type="text/css"> | |
form { | |
margin: auto; | |
width: 600px; | |
} | |
input { | |
width: 200px; | |
} | |
textarea { | |
width: 340px; | |
height: 200px; | |
} | |
</style> | |
<form method="post" action=""> | |
<label>To<label><br/> | |
<input type="text" name="to" value="" /><br/> | |
<label>From<label><br/> | |
<input type="text" name="from" value="<?= $from; ?>" /><br/> | |
<label>Subject<label><br/> | |
<input type="text" name="subject" value="Test Email" /><br/> | |
<label>Message<label><br/> | |
<textarea name="message">Hi, this is a quick test email from PHP <?= $version; ?> at <?= $fullURL; ?> on <?= $date; ?></textarea><br/> | |
<button>Submit</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment