/** * Create SMTP object and connect to server * * @param boolean True if connection should be established */ public function smtp_init($connect = false) { $this->smtp = new rcube_smtp(); if ($connect) { $this->smtp->connect(); } }
if (preg_match('/^' . $RCI->email_pattern . '$/i', $from) && preg_match('/^' . $RCI->email_pattern . '$/i', $to)) { $headers = array('From' => $from, 'To' => $to, 'Subject' => 'Test message from Roundcube'); $body = 'This is a test to confirm that Roundcube can send email.'; // send mail using configured SMTP server $CONFIG = $RCI->config; if (!empty($_POST['_smtp_user'])) { $CONFIG['smtp_user'] = $_POST['_smtp_user']; } if (!empty($_POST['_smtp_pass'])) { $CONFIG['smtp_pass'] = $_POST['_smtp_pass']; } $mail_object = new Mail_mime(); $send_headers = $mail_object->headers($headers); $head = $mail_object->txtHeaders($send_headers); $SMTP = new rcube_smtp(); $SMTP->connect(rcube_utils::parse_host($RCI->getprop('smtp_server')), $RCI->getprop('smtp_port'), $CONFIG['smtp_user'], $CONFIG['smtp_pass']); $status = $SMTP->send_mail($headers['From'], $headers['To'], $head, $body); $smtp_response = $SMTP->get_response(); if ($status) { $RCI->pass('SMTP send'); } else { $RCI->fail('SMTP send', join('; ', $smtp_response)); } } else { $RCI->fail('SMTP send', 'Invalid sender or recipient'); } echo '</p>'; } ?> <table>
$headers = array('From' => trim($_POST['_from']), 'To' => trim($_POST['_to']), 'Subject' => 'Test message from RoundCube'); $body = 'This is a test to confirm that RoundCube can send email.'; $smtp_response = array(); // send mail using configured SMTP server if ($RCI->getprop('smtp_server')) { $CONFIG = $RCI->config; if (!empty($_POST['_smtp_user'])) { $CONFIG['smtp_user'] = $_POST['_smtp_user']; } if (!empty($_POST['_smtp_pass'])) { $CONFIG['smtp_pass'] = $_POST['_smtp_pass']; } $mail_object = new rcube_mail_mime(); $send_headers = $mail_object->headers($headers); $SMTP = new rcube_smtp(); $SMTP->connect(); $status = $SMTP->send_mail($headers['From'], $headers['To'], $foo = $mail_object->txtHeaders($send_headers), $body); $smtp_response = $SMTP->get_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) {