<?php
    
/**
    * o------------------------------------------------------------------------------o
    * | This package is dual licensed as GPL and a commercial license.               |
    * | If you use the code commercially (or if you don't want to be restricted by   |
    * | the GPL license), you will need the commercial license. It's only £49 (GBP - |
    * | roughly $98 depending on the exchange rate) and helps me out a lot. Thanks.  |
    * o------------------------------------------------------------------------------o
    *
    * © Copyright Richard Heyes
    */

    /**
    * Defaults
    */
    
$smtp_server    = $_GET['server'] ? $_GET['server'] : 'localhost';
    
$smtp_port      = $_GET['port'] ? $_GET['port'] : '25';
    
$smtp_helo      = $_GET['helo'] ? $_GET['helo'] : 'localhost';
    
$smtp_from      = $_GET['from'] ? $_GET['from'] : 'root@localhost';
    
$message        = $_GET['body'] ? $_GET['body'] : "\n\nThis is the body...";
    
$smtp_recipient = $_GET['recipient'] ? $_GET['recipient'] : 'root@localhost';
    
$smtp_auth      = $_GET['auth'] ? $_GET['auth'] : 0;
    
$smtp_user      = $_GET['user'] ? $_GET['user'] : '';
    
$smtp_pass      = $_GET['pass'] ? $_GET['pass'] : '';
?>

<html>
<head>
    <title>SMTP Test utility</title>
    
    <style type="text/css">
    <!--
        body {
            font-family: Arial, Verdana;
        }
    // -->
    </style>
</head>
<body>

<h1>SMTP test utility</h1>

<form action="example.php">
<table border="0">
    <tr>
        <td align="right">Server</td>
        <td><input type="text" name="server" value="<?=htmlspecialchars($smtp_server)?>" /></td>
    </tr>

    <tr>
        <td align="right">Port</td>
        <td><input type="text" name="port" value="<?=htmlspecialchars($smtp_port)?>" size="2" /></td>
    </tr>

    <tr>
        <td align="right">HELO</td>
        <td><input type="text" name="helo" value="<?=htmlspecialchars($smtp_helo)?>" /></td>
    </tr>

    <tr>
        <td align="right">From</td>
        <td><input type="text" name="from" value="<?=htmlspecialchars($smtp_from)?>" /></td>
    </tr>

    <tr>
        <td align="right">Recipient</td>
        <td><input type="text" name="recipient" value="<?=htmlspecialchars($smtp_recipient)?>" /></td>
    </tr>

    <tr>
        <td align="right" valign="top">Body</td>
        <td>
            <textarea name="body" cols="80" rows="5"><?=htmlspecialchars($message)?></textarea>
        </td>
    </tr>

    <tr>
        <td align="right">Use authentication?</td>
        <td><input type="checkbox" name="auth" value="1" <?=($smtp_auth ? 'checked' : '')?> /></td>
    </tr>

    <tr>
        <td align="right">Auth user</td>
        <td><input type="text" name="user" value="<?=htmlspecialchars($smtp_user)?>" /></td>
    </tr>

    <tr>
        <td align="right">Auth pass</td>
        <td><input type="password" name="pass" value="<?=htmlspecialchars($smtp_pass)?>" /></td>
    </tr>

    <tr>
        <td align="right" colspan="2">
            <input type="submit" value="Go &raquo;&raquo;" />
        </td>
    </tr>
</table>
    
</form>

<div style="border: 2px inset white">
    <pre style="padding-top: 0; margin-top: 0"><?php

        error_reporting
(E_ALL);
        
ini_set('display_errors', 1);

        require_once(
'smtp.php');
        
        
###############################################
        
try {
            
$smtp = new SMTP($smtp_server, $smtp_port, $smtp_helo, $smtp_auth, $smtp_user, $smtp_pass);
            
$smtp->dbug = true;
            
$smtp->Connect();
            
$smtp->Send(array($smtp_recipient),                                     // Array of recipient addresses
                        
$smtp_from,                                                 // SMTP From address
                        
array('Subject' => 'The subject',
                              
'To'      => $smtp_recipient,
                              
'From'    => $smtp_from), // The emails headers
                        
$message);                                                // The emails body (phwoar...)
        
        
} catch (SMTPException $e) {
            echo
$e->GetMessage();
        }
        
###############################################
    
?>
    </pre>
</div>

</body>
</html>