summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2008-02-27 14:23:41 +0000
committerthomascube <thomas@roundcube.net>2008-02-27 14:23:41 +0000
commitfa7539e7aded38fd87f81d5db083b7e3b1af0547 (patch)
treec6fb0fae4c2b4c7dcccc390e593a5d1903ea19cd
parente18d04468edc17280b52440897f72434440fa07a (diff)
Send test message with mail() if no SMTP server configured; show input fields for SMTP auth if necessary
-rw-r--r--installer/rcube_install.php4
-rw-r--r--installer/test.php64
2 files changed, 54 insertions, 14 deletions
diff --git a/installer/rcube_install.php b/installer/rcube_install.php
index 44d453153..65fbe097b 100644
--- a/installer/rcube_install.php
+++ b/installer/rcube_install.php
@@ -95,14 +95,14 @@ class rcube_install
* @param string Default value
* @return string The property value
*/
- function getprop($name, $default = null)
+ function getprop($name, $default = '')
{
$value = isset($_REQUEST["_$name"]) ? $_REQUEST["_$name"] : $this->config[$name];
if ($name == 'des_key' && !isset($_REQUEST["_$name"]))
$value = self::random_key(24);
- return $value !== null ? $value : $default;
+ return $value !== null && $value !== '' ? $value : $default;
}
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 @@
<h3>Check config files</h3>
<?php
+require_once 'include/rcube_html.inc';
+
$read_main = is_readable('../config/main.inc.php');
$read_db = is_readable('../config/db.inc.php');
@@ -125,8 +127,27 @@ if ($db_working) {
<p>
Server: <?php echo $RCI->getprop('smtp_server', 'PHP mail()'); ?><br />
Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
-User: <?php echo $RCI->getprop('smtp_user', '(none)'); ?><br />
-Password: <?php echo $RCI->getprop('smtp_pass', '(none)'); ?><br />
+
+<?php
+
+if ($RCI->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<br />";
+ echo "Password: $pass<br />";
+}
+
+?>
</p>
<?php
@@ -141,23 +162,42 @@ if (isset($_POST['sendmail']) && !empty($_POST['_from']) && !empty($_POST['_to']
if (preg_match('/^' . $RCI->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');