Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick & Dirty PHP Mail Test Script
<?php
/*
DONT FORGET TO DELETE THIS SCRIPT WHEN FINISHED!
*/
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = 'webmaster@example.com';
/*
ini_set( 'SMTP', 'smtp.example.com' );
ini_set( 'SMTP_PORT', 25 );
ini_set( 'sendmail_from', $from );
*/
$server = array(
'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR', 'SERVER_PORT',
'SERVER_ADMIN', 'SERVER_SIGNATURE', 'SERVER_SOFTWARE',
'REMOTE_ADDR', 'DOCUMENT_ROOT', 'REQUEST_URI',
'SCRIPT_NAME', 'SCRIPT_FILENAME',
);
$to = ( isset( $_GET['email'] ) ? $_GET['email'] : FALSE );
$subject = 'Mail Test Successful for ' . $_SERVER['HTTP_HOST'];
$message = '';
if ( ! $to )
{
echo '<strong>Set $_GET[\'email\'].</strong>';
exit;
};
foreach ( $server as $s )
{
$message .= sprintf( '%s: %s', $s, $_SERVER[$s] ) . PHP_EOL;
};
$headers = 'From: ' . $from . PHP_EOL
. 'Reply-To: ' . $from . PHP_EOL
. 'X-Mailer: PHP/' . phpversion();
if ( isset( $_GET['send'] ) && $_GET['send'] === 'true' )
{
$success = mail( $to, $subject, $message, $headers );
}
else
{
echo '<strong>Set &quot;<a href="./?email=' . $to . '&send=true">'
. './?email=' . $to . '&send=true</a>&quot; to send a test e-mail.</strong>';
};
if ( isset( $success ) )
{
echo 'E-mail sent to: ' . $to;
echo '<br />';
echo 'Successful mail?: <strong ' . ( $success ? 'style="color:green;">YES' : 'style="color:red;">NO' ) . '</strong>';
}
else
{
echo '<br />';
echo 'E-mail set as: '.$to;
};
echo '<hr />';
echo '<style> * { font-family: Helvetica, Arial, sans-serif; } th { text-align: left; } td { padding: 3px 5px; } </style>';
echo '<table>';
foreach ( $server as $s )
{
echo '<tr><th>$_SERVER[\'' . $s . '\']</th><td>' . $_SERVER[$s] . '</td></tr>';
};
echo '</table>';
if ( isset( $success ) )
{
echo '<!--';
var_dump( $success );
echo '-->';
};
?>
@stuarteske

This comment has been minimized.

Copy link

stuarteske commented Apr 19, 2014

Cool script, thank you for sharing.

@erfinestra1977

This comment has been minimized.

Copy link

erfinestra1977 commented Jan 20, 2015

Give me error "Set $_GET['email']." Why? Thank you

@mkot0791

This comment has been minimized.

Copy link

mkot0791 commented Feb 16, 2015

I'm also getting this Set $_GET['email'] message. Any idea?

Thanks in advance

@theinhlamaw

This comment has been minimized.

Copy link

theinhlamaw commented Feb 23, 2015

This script doesn't have HTML form to accept the recipient email address. So you can test this script by passing GET parameters.

http:///yourhost/mail-test.php?email=info@example.com&send=true

@Porrapat

This comment has been minimized.

Copy link

Porrapat commented Nov 6, 2015

Thank you. It's very useful.

@Topcoder01

This comment has been minimized.

Copy link

Topcoder01 commented Jul 5, 2016

Yeah awesome script, I use it like this.

http:///yourhost/mail-test.php?email=mailtest@unlocktheinbox.com&send=true

So the above sends an email to this mail tester and you get a response back with the details of your configuration.

@cybexin

This comment has been minimized.

Copy link

cybexin commented Mar 12, 2018

how about enabling SMTP authentication?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.