I am not trying to send an email, I only want to know if the the account information provided is good or not.
The problem is I get a fatal error upon failure!
If someone provides valid account information then "NULL" is returned. If they provide invalid information then a I get a fatal error.
I want "TRUE" to be returned if the account is valid and "FALSE" to be returned if the account is invalid.
Code: Select all
<?php
require_once 'Swift/Connection/SMTP.php';
require_once 'Swift/Authenticator/LOGIN.php';
require_once 'Swift.php';
if ( isset( $_POST[ 'f' ] ) ) {
$f = $_POST[ 'f' ];
if ( isset( $f['smtp_user'] ) && !empty( $f['smtp_user'] ) ) {
} else {
$f['smtp_server'] = '';
}
} else {
$f['smtp_server'] = 'smtp.example.com';
$f['smtp_port'] = '25';
$f['smtp_user'] = 'admin@example.com';
$f['smtp_password'] = '';
}
if ( isset( $_POST[ 'cmd' ] ) ) {
$cmd = $_POST[ 'cmd' ];
} else {
$cmd = '';
}
if ( $cmd == 'check' ) {
$smtp_conn = & new Swift_Connection_SMTP( $f['smtp_server'] );
if ( isset( $f['smtp_user'] ) && !empty( $f['smtp_user'] ) ) {
$smtp_conn->setUsername( $f['smtp_user'] );
}
if ( isset( $f['smtp_password'] ) && !empty( $f['smtp_password'] ) ) {
$smtp_conn->setPassword( $f['smtp_password'] );
}
if ( isset( $f['smtp_port'] ) && !empty( $f['smtp_port'] ) ) {
$smtp_conn->setPort( $f['smtp_port'] );
}
$smtp_conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift =& new Swift( $smtp_conn );
echo '<p style="width: 350px; padding: 20px; border: 3px solid #cc5555">';
var_dump( $swift->connect() );
echo '</p>';
}
?>
<html>
<head>
</head>
<body>
<div style="padding-top: 20px;">
<form name="categories" action="./" method="post">
<input type="hidden" name="cmd" value="check"/>
<table cellspacing="1" cellpadding="2" border="0" width="450" class="admin_table" summary="settings">
<tr>
<td class="text_normal_9pt_left">SMTP Server:</td>
<td class="text_normal_9pt_left"><input type="text" name="f[smtp_server]" value="<?php if (!empty($f['smtp_server'])) { echo( $f['smtp_server'] ); };?>" maxlength="255" style="width: 250px;"/></td>
</tr>
<tr>
<td class="text_normal_9pt_left">SMTP Server Port:</td>
<td class="text_normal_9pt_left"><input type="text" name="f[smtp_port]" value="<?php if (!empty($f['smtp_port'])) { echo( $f['smtp_port'] ); };?>" maxlength="255" style="width: 250px;"/></td>
</tr>
<tr>
<td class="text_normal_9pt_left">SMTP Username:</td>
<td class="text_normal_9pt_left"><input type="text" name="f[smtp_user]" value="<?php if (!empty($f['smtp_user'])) { echo( $f['smtp_user'] ); };?>" maxlength="255" style="width: 250px;"/></td>
</tr>
<tr>
<td class="text_normal_9pt_left">SMTP Password:</td>
<td class="text_normal_9pt_left"><input type="password" name="f[smtp_password]" value="<?php if (!empty($f['smtp_password'])) { echo( $f['smtp_password'] ); };?>" maxlength="255" style="width: 250px;"/></td>
</tr>
<tr>
<td class="text_normal_9pt_left"></td>
<td class="text_normal_9pt_left"><input type="submit" name="check" value="Check" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>