From fa7539e7aded38fd87f81d5db083b7e3b1af0547 Mon Sep 17 00:00:00 2001 From: thomascube Date: Wed, 27 Feb 2008 14:23:41 +0000 Subject: Send test message with mail() if no SMTP server configured; show input fields for SMTP auth if necessary --- installer/test.php | 64 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 12 deletions(-) (limited to 'installer/test.php') diff --git a/installer/test.php b/installer/test.php index d0cb77716..8a8b3457d 100644 --- a/installer/test.php +++ b/installer/test.php @@ -3,6 +3,8 @@

Check config files

Server: getprop('smtp_server', 'PHP mail()'); ?>
Port: getprop('smtp_port'); ?>
-User: getprop('smtp_user', '(none)'); ?>
-Password: getprop('smtp_pass', '(none)'); ?>
+ +getprop('smtp_server')) { + $user = $RCI->getprop('smtp_user', '(none)'); + $pass = $RCI->getprop('smtp_pass', '(none)'); + + if ($user == '%u') { + $user_field = new textfield(array('name' => '_user')); + $user = $user_field->show(); + } + if ($pass == '%p') { + $pass_field = new passwordfield(array('name' => '_pass')); + $pass = $pass_field->show(); + } + + echo "User: $user
"; + echo "Password: $pass
"; +} + +?>

email_pattern . '$/i', trim($_POST['_from'])) && preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) { - $recipients = trim($_POST['_to']); - $headers = array( 'From' => trim($_POST['_from']), - 'To' => $recipients, + 'To' => trim($_POST['_to']), 'Subject' => 'Test message from RoundCube', ); $body = 'This is a test to confirm that RoundCube can send email.'; - - $mail_object = new rc_mail_mime(); - $send_headers = $mail_object->headers($headers); - $smtp_response = array(); - $status = smtp_mail($headers['From'], $recipients, - ($foo = $mail_object->txtHeaders($send_headers)), - $body, $smtp_response); + + // send mail using configured SMTP server + if ($RCI->getprop('smtp_server')) { + $CONFIG = $RCI->config; + + if (!empty($_POST['_user'])) + $CONFIG['smtp_user'] = $_POST['_user']; + if (!empty($_POST['_pass'])) + $CONFIG['smtp_pass'] = $_POST['_pass']; + + $mail_object = new rc_mail_mime(); + $send_headers = $mail_object->headers($headers); + + $status = smtp_mail($headers['From'], $headers['To'], + ($foo = $mail_object->txtHeaders($send_headers)), + $body, $smtp_response); + } + else { // use mail() + $header_str = 'From: ' . $headers['From']; + + if (ini_get('safe_mode')) + $status = mail($headers['To'], $headers['Subject'], $body, $header_str); + else + $status = mail($headers['To'], $headers['Subject'], $body, $header_str, '-f'.$headers['From']); + + if (!$status) + $smtp_response[] = 'Mail delivery with mail() failed. Check your error logs for details'; + } if ($status) { $RCI->pass('SMTP send'); -- cgit v1.2.3