Test of your e-mail configuration
ERROR: Please provide a valid e-mail address in testmail.php.
' . PHP_EOL;
} else {
if ($configFileExists && $configCIFileExists) {
include $pathCIConfigFile;
include $pathConfigFile;
try {
//Include shipped PHPMailer library
$mail = new PHPMailer(true); //true => throw exceptions on error
$mail->SMTPDebug = 1; //Errors and messages
$mail->Debugoutput = function($str, $level) {
echo nl2br($str);
};
//Test if we use SMTP protocol
if (strcasecmp($config['protocol'], 'smtp') == 0) {
echo 'INFO: Selecting SMTP Protocol.
' . PHP_EOL;
$mail->IsSMTP();
$mail->Host = $config['smtp_host'];
$mail->Port = $config['smtp_port'];
$mail->SMTPAutoTLS = $config['smtp_auto_tls'];
if (strpos($config['smtp_port'], 'gmail') !== false) {
echo 'INFO: Using GMAIL.
' . PHP_EOL;
}
}
//Test if we use sendmail
if (strcasecmp($config['protocol'], 'sendmail') == 0) {
echo 'INFO: Selecting sendmail.
' . PHP_EOL;
$mail->IsSendmail();
if (array_key_exists('mailpath', $config)) {
if ($config['mailpath'] != '') {
echo 'INFO: Changing sendmail path.
' . PHP_EOL;
ini_set('sendmail_path', $config['mailpath']);
}
}
}
//GMAIL requires _smtp_auth set to TRUE
if ($config['smtp_auth'] === TRUE) {
echo 'INFO: SMTP with authentication.
' . PHP_EOL;
$mail->SMTPAuth = true;
$mail->Username = $config['smtp_user'];
$mail->Password = $config['smtp_pass'];
}
//GMAIL requires smtp_crypto set to tls
if ($config['smtp_crypto'] != '') {
echo 'INFO: SMTP with crypto.
' . PHP_EOL;
$mail->SMTPSecure = $config['smtp_crypto'];
}
$mail->CharSet = $config['charset'];
$mail->AddAddress(EMAIL_ADDRESS, "Test e-mail");
$mail->SetFrom($config['from_mail'], "Jorani application");
$mail->Subject = "Test Message";
$mail->Body = 'This is a test.';
$mail->Send();
echo 'INFO: Message sent.
' . PHP_EOL;
} catch (phpmailerException $e) {
echo 'ERROR: PHPMailer has encountered an error.
' . PHP_EOL;
$text = $e->errorMessage();
$text = iconv(mb_detect_encoding($text, mb_detect_order(), true), "UTF-8", $text);
echo $text . PHP_EOL;
} catch (Exception $e) {
echo 'ERROR: Unexpected error.
' . PHP_EOL;
$text = $e->getMessage();
$text = iconv(mb_detect_encoding($text, mb_detect_order(), true), "UTF-8", $text);
echo $text . PHP_EOL;
}
} else {
echo 'ERROR: The configuration doesn\'t exist.
' . PHP_EOL;
}
}
?>
Troubleshooting
In case of error, here are some additional steps: