| | |
| | | * @package Mail |
| | | */ |
| | | |
| | | // include required PEAR classes |
| | | require_once('Net/SMTP.php'); |
| | | |
| | | |
| | | // define headers delimiter |
| | | define('SMTP_MIME_CRLF', "\r\n"); |
| | | |
| | |
| | | * |
| | | * @return bool Returns TRUE on success, or FALSE on error |
| | | */ |
| | | function smtp_mail($from, $recipients, &$headers, &$body, &$response) |
| | | function smtp_mail($from, $recipients, &$headers, &$body, &$response, &$error) |
| | | { |
| | | global $SMTP_CONN, $CONFIG, $RCMAIL; |
| | | $smtp_timeout = null; |
| | | $smtp_host = $CONFIG['smtp_server']; |
| | | $smtp_port = is_numeric($CONFIG['smtp_port']) ? $CONFIG['smtp_port'] : 25; |
| | | $smtp_host_url = parse_url($CONFIG['smtp_server']); |
| | | global $SMTP_CONN, $RCMAIL; |
| | | |
| | | // let plugins alter smtp connection config |
| | | $CONFIG = $RCMAIL->plugins->exec_hook('smtp_connect', array( |
| | | 'smtp_server' => $RCMAIL->config->get('smtp_server'), |
| | | 'smtp_port' => $RCMAIL->config->get('smtp_port', 25), |
| | | 'smtp_user' => $RCMAIL->config->get('smtp_user'), |
| | | 'smtp_pass' => $RCMAIL->config->get('smtp_pass'), |
| | | 'smtp_auth_type' => $RCMAIL->config->get('smtp_auth_type'), |
| | | 'smtp_helo_host' => $RCMAIL->config->get('smtp_helo_host'), |
| | | )); |
| | | |
| | | $smtp_timeout = null; |
| | | $smtp_host = str_replace('%h', $_SESSION['imap_host'], $CONFIG['smtp_server']); |
| | | $smtp_port = is_numeric($CONFIG['smtp_port']) ? $CONFIG['smtp_port'] : 25; |
| | | $smtp_host_url = parse_url($smtp_host); |
| | | |
| | | // overwrite port |
| | | if (isset($smtp_host_url['host']) && isset($smtp_host_url['port'])) |
| | | { |
| | |
| | | |
| | | $SMTP_CONN = new Net_SMTP($smtp_host, $smtp_port, $helo_host); |
| | | |
| | | if($RCMAIL->config->get('smtp_debug')) |
| | | $SMTP_CONN->setDebug(true, 'smtp_debug_handler'); |
| | | |
| | | // try to connect to server and exit on failure |
| | | $result = $SMTP_CONN->connect($smtp_timeout); |
| | | if (PEAR::isError($result)) |
| | | { |
| | | $SMTP_CONN = null; |
| | | $response[] = "Connection failed: ".$result->getMessage(); |
| | | $error = array('label' => 'smtpconnerror', 'vars' => array('code' => $SMTP_CONN->_code)); |
| | | $SMTP_CONN = null; |
| | | return FALSE; |
| | | } |
| | | |
| | |
| | | |
| | | if (PEAR::isError($result)) |
| | | { |
| | | smtp_reset(); |
| | | $error = array('label' => 'smtpautherror', 'vars' => array('code' => $SMTP_CONN->_code)); |
| | | $response[] .= 'Authentication failure: ' . $result->getMessage() . ' (Code: ' . $result->getCode() . ')'; |
| | | smtp_reset(); |
| | | return FALSE; |
| | | } |
| | | } |
| | |
| | | // set From: address |
| | | if (PEAR::isError($SMTP_CONN->mailFrom($from))) |
| | | { |
| | | smtp_reset(); |
| | | $error = array('label' => 'smtpfromerror', 'vars' => array('from' => $from, 'code' => $SMTP_CONN->_code)); |
| | | $response[] .= "Failed to set sender '$from'"; |
| | | smtp_reset(); |
| | | return FALSE; |
| | | } |
| | | |
| | |
| | | $recipients = smtp_parse_rfc822($recipients); |
| | | if (PEAR::isError($recipients)) |
| | | { |
| | | $error = array('label' => 'smtprecipientserror'); |
| | | smtp_reset(); |
| | | return FALSE; |
| | | } |
| | |
| | | { |
| | | if (PEAR::isError($SMTP_CONN->rcptTo($recipient))) |
| | | { |
| | | smtp_reset(); |
| | | $error = array('label' => 'smtptoerror', 'vars' => array('to' => $recipient, 'code' => $SMTP_CONN->_code)); |
| | | $response[] .= "Failed to add recipient '$recipient'"; |
| | | smtp_reset(); |
| | | return FALSE; |
| | | } |
| | | } |
| | |
| | | unset($text_headers, $body); |
| | | |
| | | // Send the message's headers and the body as SMTP data. |
| | | if (PEAR::isError($SMTP_CONN->data($data))) |
| | | if (PEAR::isError($result = $SMTP_CONN->data($data))) |
| | | { |
| | | smtp_reset(); |
| | | $error = array('label' => 'smtperror', 'vars' => array('msg' => $result->getMessage())); |
| | | $response[] .= "Failed to send data"; |
| | | smtp_reset(); |
| | | return FALSE; |
| | | } |
| | | |
| | |
| | | { |
| | | global $SMTP_CONN; |
| | | |
| | | if (is_object($SMTP_CONN)) |
| | | if (is_object($SMTP_CONN) && is_resource($SMTP_CONN->_socket->fp)) |
| | | { |
| | | $SMTP_CONN->rset(); |
| | | smtp_disconnect(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | /* this is our own debug handler for the SMTP connection */ |
| | | function smtp_debug_handler(&$smtp, $message) |
| | | { |
| | | write_log('smtp', preg_replace('/\r\n$/', '', $message)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Take an array of mail headers and return a string containing |