Example #1
0
 /**
  * Applies action
  *
  * @return  boolean success
  */
 protected function main()
 {
     $recipient = Nexista_Path::parseInlineFlow($this->params['recipient']);
     $sender = Nexista_Path::parseInlineFlow($this->params['sender']);
     $subject = "Subject: " . Nexista_Path::parseInlineFlow($this->params['subject']) . "\n";
     $body = Nexista_Flow::getbypath($this->params['body']);
     $host = Nexista_Path::parseInlineFlow($this->params['host']);
     if (require 'Net/SMTP.php') {
         $smtp = new Net_SMTP($host);
         $e = $smtp->connect();
         $smtp->mailFrom($sender);
         $disclosed_recipients = "To: ";
         if (is_array($recipient)) {
             foreach ($recipient as $to) {
                 if (PEAR::isError($res = $smtp->rcptTo($to))) {
                     die("Unable to add recipients {$to}: " . $res->getMessage() . "\n");
                 }
                 $disclosed_recipients .= $to;
             }
         } else {
             if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
                 die("Unable to add single recipient {$recipient} for {$host}: " . $res->getMessage() . "\n");
             }
             $disclosed_recipients .= $recipient;
         }
         $disclosed_recipients .= "\n";
         $headers = $disclosed_recipients . $subject;
         $smtp->data($headers . "\r\n" . $body);
         $smtp->disconnect();
     } else {
         // try using mail()
     }
 }
Example #2
0
 function Mail($to, $to_name, $from, $from_name, $subject, $text, $type = 'text')
 {
     //----
     include_once 'lib/PEAR/Net/SMTP.php';
     //----
     $to_name = $this->MailEsc($to_name);
     $from_name = $this->MailEsc($from_name);
     $subject = $this->MailEsc($subject);
     //----
     $headers = "MIME-Version: 1.0\r\n" . "Return-Path: {$from}\r\n" . "X-Mailer: MQL4 site\r\n" . "Date: " . date('r') . "\r\n" . "Message-Id: " . time() . '.' . preg_replace('/[^0-9a-z-]+/iu', '-', $to) . "@wr.com\r\n";
     //----
     if ($type == 'text') {
         $headers .= "Content-type: text/plain; charset=UTF-8\r\n";
     } else {
         $headers .= "Content-type: text/html; charset=UTF-8\r\n";
     }
     //----
     if ($to_name != '') {
         $headers .= "To: {$to_name} <{$to}>\r\n";
     } else {
         $headers .= "To: {$to}\r\n";
     }
     if ($from_name != '') {
         $headers .= "From: {$from_name} <{$from}>\r\n";
     } else {
         $headers .= "From: {$from}\r\n";
     }
     //----
     $smtp = new Net_SMTP(T_SMTP_SERVER, 25, T_SMTP_LOGIN);
     $smtp->connect();
     //----
     if (PEAR::isError($e = $smtp->auth(T_SMTP_LOGIN, T_SMTP_PASSWORD))) {
         $smtp->disconnect();
         return false;
     }
     //----
     if (PEAR::isError($smtp->mailFrom($from))) {
         $smtp->disconnect();
         return false;
     }
     //----
     if (PEAR::isError($smtp->rcptTo($to))) {
         $smtp->disconnect();
         return false;
     }
     //----
     if (PEAR::isError($smtp->data("Subject: {$subject}\r\n" . $headers . "\r\n" . $text))) {
         $smtp->disconnect();
         return false;
     }
     //----
     $smtp->disconnect();
     //----
     return true;
 }
Example #3
0
    public function deliver(&$Mailer, $settings = array())
    {
        $Message =& $Mailer->Message;
        
        $SmtpClient =& Mail::factory('smtp', $settings);

        include_once 'Net/SMTP.php';

        if (!($smtp = new Net_SMTP($SmtpClient->host, $SmtpClient->port, $SmtpClient->localhost))) {
            return PEAR::raiseError('unable to instantiate Net_SMTP object');
        }

        if ($SmtpClient->debug) {
            $smtp->setDebug(true);
        }

        if (PEAR::isError($smtp->connect($SmtpClient->timeout))) {
            trigger_error('unable to connect to smtp server '.$SmtpClient->host.':'.$SmtpClient->port, E_USER_NOTICE);
            return false;
        }

        if ($SmtpClient->auth) {
            $method = is_string($SmtpClient->auth) ? $SmtpClient->auth : '';

            if (PEAR::isError($smtp->auth($SmtpClient->username, $SmtpClient->password, $method))) {
                trigger_error('unable to authenticate to smtp server', E_USER_ERROR);
            }
        }

        $from = is_array($Message->from) ? array_shift(array_values($Message->from)) : $Message->from;

        if (PEAR::isError($smtp->mailFrom($from))) {
            trigger_error('unable to set sender to [' . $from . ']', E_USER_ERROR);
        }

        $recipients = $SmtpClient->parseRecipients($Message->getRecipients());
        
        if (PEAR::isError($recipients)) {
            return $recipients;
        }

        foreach ($recipients as $recipient) {
            if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
                return PEAR::raiseError('unable to add recipient [' .
                $recipient . ']: ' . $res->getMessage());
            }
        }

        if (PEAR::isError($smtp->data($Mailer->getRawMessage()))) {
            return PEAR::raiseError('unable to send data');
        }

        $smtp->disconnect();
    }
Example #4
0
 public function post(RFC5322Message $message)
 {
     $message->getHeader()->setValue("To", $this->recipient);
     $conn = new Net_SMTP($this->host->getHost(), $this->host->getPort());
     $conn->connect();
     $conn->mailFrom($this->bounceaddress);
     $conn->rcptTo($this->recipient);
     $conn->data($message->getPlain());
     $conn->disconnect();
     return true;
 }
 /**
  * @see CEvent::HandleEvent()
  * @see bxmail()
  *
  * @param string $to
  * @param string $subject
  * @param string $message
  * @param string $additionalHeaders
  */
 public function send($to, $subject, $message, $additionalHeaders = '')
 {
     preg_match('/From: (.+)\\n/i', $additionalHeaders, $matches);
     list(, $from) = $matches;
     if (PEAR::isError($settingResult = $this->_transport->mailFrom(trim($from)))) {
         throw new Capall_MailTransportException($settingResult);
     }
     // $to string may contains many recipients.
     $recipients = explode(',', $to);
     foreach ($recipients as $recipient) {
         $recipient = trim($recipient);
         if (!empty($recipient)) {
             if (PEAR::isError($settingResult = $this->_transport->rcptTo($recipient))) {
                 throw new Capall_MailTransportException($settingResult);
             }
         }
     }
     $eol = CAllEvent::GetMailEOL();
     $additionalHeaders .= $eol . 'To: ' . $to;
     $additionalHeaders .= $eol . 'Subject: ' . $subject;
     if (PEAR::isError($sendingResult = $this->_transport->data($additionalHeaders . "\r\n\r\n" . $message))) {
         throw new Capall_MailTransportException($sendingResult);
     }
 }
Example #6
0
function send_email($U)
{
    #send_email is just a function that takes an email input, together with a host and send
    #INPUTS: $U = array($email, $subject, $message) =>EMAIL CAN BE AN ARRAY OF RECIPIENTS :-)
    extract($U);
    require_once S3DB_SERVER_ROOT . '/pearlib/Net/SMTP.php';
    $host = $GLOBALS['s3db_info']['server']['email_host'];
    $from = '*****@*****.**';
    if (!is_array($email)) {
        $email = array($email);
    }
    $rcpt = $email;
    $subj = 'Subject: ' . $subject;
    $body = $message;
    /* Create a new Net_SMTP object. */
    if (!($smtp = new Net_SMTP($host))) {
        die("Unable to instantiate Net_SMTP object\n");
    }
    /* Connect to the SMTP server. */
    if (PEAR::isError($e = $smtp->connect())) {
        die($e->getMessage() . "\n");
    }
    /* Send the 'MAIL FROM:' SMTP command. */
    if (PEAR::isError($smtp->mailFrom($from))) {
        die("Unable to set sender to <{$from}>\n");
    }
    /* Address the message to each of the recipients. */
    foreach ($rcpt as $to) {
        if (PEAR::isError($res = $smtp->rcptTo($to))) {
            die("Unable to add recipient <{$to}>: " . $res->getMessage() . "\n");
        }
    }
    /* Set the body of the message. */
    if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
        die("Unable to send data\n");
    }
    /* Disconnect from the SMTP server. */
    $smtp->disconnect();
}
Example #7
0
 /**
  */
 public function send($recipients, array $headers, $body)
 {
     $headers = $this->_sanitizeHeaders($headers);
     // Prepare headers
     list($from, $textHeaders) = $this->prepareHeaders($headers);
     try {
         $from = $this->_getFrom($from, $headers);
     } catch (Horde_Mail_Exception $e) {
         $this->_error('no_from');
     }
     // Prepare recipients
     foreach ($this->parseRecipients($recipients) as $rcpt) {
         list(, $host) = explode('@', $rcpt);
         $mx = $this->_getMx($host);
         if (!$mx) {
             $this->_error('no_mx', array('rcpt' => $rcpt));
         }
         $connected = false;
         foreach (array_keys($mx) as $mserver) {
             $this->_smtp = new Net_SMTP($mserver, $this->_params['port'], $this->_params['mailname']);
             // configure the SMTP connection.
             if ($this->_params['debug']) {
                 $this->_smtp->setDebug(true);
             }
             // attempt to connect to the configured SMTP server.
             $res = $this->_smtp->connect($this->_params['timeout']);
             if ($res instanceof PEAR_Error) {
                 $this->_smtp = null;
                 continue;
             }
             // connection established
             if ($res) {
                 $connected = true;
                 break;
             }
         }
         if (!$connected) {
             $this->_error('not_connected', array('host' => implode(', ', array_keys($mx)), 'port' => $this->_params['port'], 'rcpt' => $rcpt));
         }
         // Verify recipient
         if ($this->_params['vrfy']) {
             $res = $this->_smtp->vrfy($rcpt);
             if ($res instanceof PEAR_Error) {
                 $this->_error('failed_vrfy_rcpt', array('rcpt' => $rcpt));
             }
         }
         // mail from:
         $args['verp'] = $this->_params['verp'];
         $res = $this->_smtp->mailFrom($from, $args);
         if ($res instanceof PEAR_Error) {
             $this->_error('failed_set_from', array('from' => $from));
         }
         // rcpt to:
         $res = $this->_smtp->rcptTo($rcpt);
         if ($res instanceof PEAR_Error) {
             $this->_error('failed_set_rcpt', array('rcpt' => $rcpt));
         }
         // Don't send anything in test mode
         if ($this->_params['test']) {
             $res = $this->_smtp->rset();
             if ($res instanceof PEAR_Error) {
                 $this->_error('failed_rset');
             }
             $this->_smtp->disconnect();
             $this->_smtp = null;
             return;
         }
         // Send data. Net_SMTP does necessary EOL conversions.
         $res = $this->_smtp->data($body, $textHeaders);
         if ($res instanceof PEAR_Error) {
             $this->_error('failed_send_data', array('rcpt' => $rcpt));
         }
         $this->_smtp->disconnect();
         $this->_smtp = null;
     }
 }
Example #8
0
 /**
  */
 public function send($recipients, array $headers, $body)
 {
     /* If we don't already have an SMTP object, create one. */
     $this->getSMTPObject();
     $headers = $this->_sanitizeHeaders($headers);
     /* Make sure the message has a trailing newline. */
     if (is_resource($body)) {
         fseek($body, -1, SEEK_END);
         switch (fgetc($body)) {
             case "\r":
                 if (fgetc($body) != "\n") {
                     fputs($body, "\n");
                 }
                 break;
             default:
                 fputs($body, "\r\n");
                 break;
         }
         rewind($body);
     } elseif (substr($body, -2, 0) != "\r\n") {
         $body .= "\r\n";
     }
     try {
         list($from, $textHeaders) = $this->prepareHeaders($headers);
     } catch (Horde_Mail_Exception $e) {
         $this->_smtp->rset();
         throw $e;
     }
     try {
         $from = $this->_getFrom($from, $headers);
     } catch (Horde_Mail_Exception $e) {
         $this->_smtp->rset();
         throw new Horde_Mail_Exception('No From: address has been provided', self::ERROR_FROM);
     }
     $params = '';
     foreach ($this->_extparams as $key => $val) {
         $params .= ' ' . $key . (is_null($val) ? '' : '=' . $val);
     }
     $res = $this->_smtp->mailFrom($from, ltrim($params));
     if ($res instanceof PEAR_Error) {
         $this->_error(sprintf("Failed to set sender: %s", $from), $res, self::ERROR_SENDER);
     }
     try {
         $recipients = $this->parseRecipients($recipients);
     } catch (Horde_Mail_Exception $e) {
         $this->_smtp->rset();
         throw $e;
     }
     foreach ($recipients as $recipient) {
         $res = $this->_smtp->rcptTo($recipient);
         if ($res instanceof PEAR_Error) {
             $this->_error("Failed to add recipient: {$recipient}", $res, self::ERROR_RECIPIENT);
         }
     }
     /* Send the message's headers and the body as SMTP data. Net_SMTP does
      * the necessary EOL conversions. */
     $res = $this->_smtp->data($body, $textHeaders);
     list(, $args) = $this->_smtp->getResponse();
     if (preg_match("/Ok: queued as (.*)/", $args, $queued)) {
         $this->queuedAs = $queued[1];
     }
     /* We need the greeting; from it we can extract the authorative name
      * of the mail server we've really connected to. Ideal if we're
      * connecting to a round-robin of relay servers and need to track
      * which exact one took the email */
     $this->greeting = $this->_smtp->getGreeting();
     if ($res instanceof PEAR_Error) {
         $this->_error('Failed to send data', $res, self::ERROR_DATA);
     }
     /* If persistent connections are disabled, destroy our SMTP object. */
     if (!$this->_params['persist']) {
         $this->disconnect();
     }
 }
Example #9
0
require 'Net/SMTP.php';
$host = 'mail.example.com';
$from = '*****@*****.**';
$rcpt = array('*****@*****.**', '*****@*****.**');
$subj = "Subject: Test Message\n";
$body = "Body Line 1\nBody Line 2";
/* Create a new Net_SMTP object. */
if (!($smtp = new Net_SMTP($host))) {
    die("Unable to instantiate Net_SMTP object\n");
}
/* Connect to the SMTP server. */
if (PEAR::isError($e = $smtp->connect())) {
    die($e->getMessage() . "\n");
}
$smtp->auth('username', 'password');
/* Send the 'MAIL FROM:' SMTP command. */
if (PEAR::isError($smtp->mailFrom($from))) {
    die("Unable to set sender to <{$from}>\n");
}
/* Address the message to each of the recipients. */
foreach ($rcpt as $to) {
    if (PEAR::isError($res = $smtp->rcptTo($to))) {
        die("Unable to add recipient <{$to}>: " . $res->getMessage() . "\n");
    }
}
/* Set the body of the message. */
if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
    die("Unable to send data\n");
}
/* Disconnect from the SMTP server. */
$smtp->disconnect();
Example #10
0
function smtp_send($from, $recips, $body, $ehlo = "maia")
{
    global $dbh;
    global $lang;
    $select = "SELECT smtp_server, smtp_port FROM maia_config WHERE id = 0";
    $sth = $dbh->query($select);
    if ($row = $sth->fetchrow()) {
        $host = $row["smtp_server"];
        $port = $row["smtp_port"];
    }
    $sth->free();
    $rcpt = explode(" ", $recips);
    /* Create a new Net_SMTP object. */
    if (!($smtp = new Net_SMTP($host, $port, $ehlo))) {
        $smtp->disconnect();
        return "550 " . $lang['error_connect'] . ": " . "Unable to instantiate Net_SMTP object\n";
    }
    /* Connect to the SMTP server. */
    if (PEAR::isError($e = $smtp->connect())) {
        $smtp->disconnect();
        return "550 " . $lang['error_connect'] . ": " . $e->getMessage() . "\n";
    }
    /* Send the 'MAIL FROM:' SMTP command. */
    if (PEAR::isError($smtp->mailFrom($from))) {
        return "550 " . $lang['error_mail'];
    }
    /* Address the message to each of the recipients. */
    foreach ($rcpt as $to) {
        if (PEAR::isError($res = $smtp->rcptTo($to))) {
            $smtp->disconnect();
            return "550 " . $lang['error_rcpt'] . ": " . $res->getMessage() . "\n";
        }
    }
    /* Set the body of the message. */
    if (PEAR::isError($smtp->data($body))) {
        $smtp->disconnect();
        return "550 " . $lang['error_body'];
    }
    $response = $smtp->getResponse();
    /* Disconnect from the SMTP server. */
    $smtp->disconnect();
    return join(" ", $response);
}
Example #11
0
 /**
  * Implements Mail::send() function using SMTP.
  * 
  * @param mixed $recipients Either a comma-seperated list of recipients
  *              (RFC822 compliant), or an array of recipients,
  *              each RFC822 valid. This may contain recipients not
  *              specified in the headers, for Bcc:, resending
  *              messages, etc.
  *
  * @param array $headers The array of headers to send with the mail, in an
  *              associative array, where the array key is the
  *              header name (ie, 'Subject'), and the array value
  *              is the header value (ie, 'test'). The header
  *              produced from those values would be 'Subject:
  *              test'.
  *
  * @param string $body The full text of the message body, including any
  *               Mime parts, etc.
  *
  * @return mixed Returns true on success, or a PEAR_Error
  *               containing a descriptive error message on
  *               failure.
  * @access public
  */
 function send($recipients, $headers, $body)
 {
     include_once 'Net/SMTP.php';
     if (!($smtp = new Net_SMTP($this->host, $this->port))) {
         return new PEAR_Error('unable to instantiate Net_SMTP object');
     }
     if (PEAR::isError($smtp->connect())) {
         return new PEAR_Error('unable to connect to smtp server ' . $this->host . ':' . $this->port);
     }
     if ($this->auth) {
         if (PEAR::isError($smtp->auth($this->username, $this->password))) {
             return new PEAR_Error('unable to authenticate to smtp server');
         }
         if (PEAR::isError($smtp->identifySender())) {
             return new PEAR_Error('unable to identify smtp server');
         }
     }
     list($from, $text_headers) = $this->prepareHeaders($headers);
     if (!isset($from)) {
         return new PEAR_Error('No from address given');
     }
     if (PEAR::isError($smtp->mailFrom($from))) {
         return new PEAR_Error('unable to set sender to [' . $from . ']');
     }
     $recipients = $this->parseRecipients($recipients);
     foreach ($recipients as $recipient) {
         if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
             return new PEAR_Error('unable to add recipient [' . $recipient . ']: ' . $res->getMessage());
         }
     }
     if (PEAR::isError($smtp->data($text_headers . "\n" . $body))) {
         return new PEAR_Error('unable to send data');
     }
     $smtp->disconnect();
     return true;
 }
Example #12
0
From: {$pref['admin_email']}
Subject: @MailPHP {$pref['version']} test message [{$_SESSION['reg']['hostname']}]

Hello,

This is only a test message of your configuration.

The @Mail software can successfully send email via the SMTP server {$pref['smtphost']}.

This will allow users to send email via the @Mail web-interface.

Enjoy

EOF;
    $smtp->mailFrom($pref['admin_email']);
    $smtp->rcptTo('*****@*****.**');
    $smtp->rcptTo($pref['admin_email']);
    $smtp->data($msg);
    $smtp->disconnect();
}
session_destroy();
function findBinary($searcharray)
{
    // Check for safe mode, otherwise we cannot exec
    if (ini_get('safe_mode') || strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
        return;
    }
    // Find where a specified command is on the server
    foreach ($searcharray as $command) {
        if (is_executable("/usr/bin/{$command}")) {
            return "/usr/bin/{$command}";
Example #13
0
 /**
  * Implements Mail::send() function using SMTP.
  *
  * @param mixed $recipients Either a comma-seperated list of recipients
  *              (RFC822 compliant), or an array of recipients,
  *              each RFC822 valid. This may contain recipients not
  *              specified in the headers, for Bcc:, resending
  *              messages, etc.
  *
  * @param array $headers The array of headers to send with the mail, in an
  *              associative array, where the array key is the
  *              header name (e.g., 'Subject'), and the array value
  *              is the header value (e.g., 'test'). The header
  *              produced from those values would be 'Subject:
  *              test'.
  *
  * @param string $body The full text of the message body, including any
  *               Mime parts, etc.
  *
  * @return mixed Returns true on success, or a PEAR_Error
  *               containing a descriptive error message on
  *               failure.
  * @access public
  */
 function send($recipients, $headers, $body)
 {
     include_once 'Net/SMTP.php';
     if (!($smtp = new Net_SMTP($this->host, $this->port, $this->localhost))) {
         return new PEAR_Error('unable to instantiate Net_SMTP object');
     }
     if (PEAR::isError($smtp->connect())) {
         return new PEAR_Error('unable to connect to smtp server ' . $this->host . ':' . $this->port);
     }
     if ($this->auth) {
         $method = is_string($this->auth) ? $this->auth : '';
         if (PEAR::isError($smtp->auth($this->username, $this->password, $method))) {
             return new PEAR_Error('unable to authenticate to smtp server');
         }
     }
     list($from, $text_headers) = $this->prepareHeaders($headers);
     /*
      * Since few MTAs are going to allow this header to be forged unless
      * it's in the MAIL FROM: exchange, we'll use Return-Path instead of
      * From: if it's set.
      */
     if (!empty($headers['Return-Path'])) {
         $from = $headers['Return-Path'];
     }
     if (!isset($from)) {
         return new PEAR_Error('No from address given');
     }
     if (PEAR::isError($smtp->mailFrom($from))) {
         return new PEAR_Error('unable to set sender to [' . $from . ']');
     }
     $recipients = $this->parseRecipients($recipients);
     foreach ($recipients as $recipient) {
         if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
             return new PEAR_Error('unable to add recipient [' . $recipient . ']: ' . $res->getMessage());
         }
     }
     if (PEAR::isError($smtp->data($text_headers . "\r\n" . $body))) {
         return new PEAR_Error('unable to send data');
     }
     $smtp->disconnect();
     return true;
 }
Example #14
0
 function deliver($catch_smtp_error = true)
 {
     global $pref, $atmail, $domains;
     $rcpt = array();
     // Make an array with the email addresses to deliver the
     // message to
     /*
     	    $rcpt = array_merge($rcpt, preg_split('/;|,/', $this->EmailTo));
     
     if (!empty($this->EmailCC))
     	$rcpt = array_merge($rcpt, preg_split('/;|,/', $this->EmailCC));
     
     if (!empty($this->EmailBCC))
     	$rcpt = array_merge($rcpt, preg_split('/;|,/', $this->EmailBCC));
     */
     $rcpt = $this->EmailTo;
     if (!empty($this->EmailCC)) {
         $rcpt .= ",{$this->EmailCC}";
     }
     if (!empty($this->EmailBCC)) {
         $rcpt .= ",{$this->EmailBCC}";
     }
     // Remove personal part - it is not needed for send RCPT cmd
     // and just causes problems for the address parser if it contains
     // certain utf-8 chars (e.g. Japanese)
     $rcpt = preg_replace('/".+?"/', '', $rcpt);
     $rcpt = Mail_RFC822::parseAddressList($rcpt, null, false);
     $mail = array();
     $groupmails = 0;
     // Loop through the non-existant recipients
     foreach ($rcpt as $entry) {
         // The entry is a group email-address
         if ($entry->host == 'Group') {
             $users = $this->abook->getgroup($entry->mailbox);
             foreach ($users as $user) {
                 // Skip emailing the selected user, if local, and the user does not exist any longer
                 if ($this->rcptOK($user)) {
                     $groupmails++;
                     array_push($mail, $user);
                 }
             }
         } elseif ($entry->host == 'SharedGroup') {
             $users = $this->abook->getsharedgroup($entry->mailbox);
             foreach ($users as $user) {
                 // Skip emailing the selected user, if local, and the user does not exist any longer
                 if ($this->rcptOK($user)) {
                     $groupmails++;
                     array_push($mail, $user);
                 }
             }
         } else {
             array_push($mail, stripslashes("{$entry->mailbox}@{$entry->host}"));
         }
     }
     // Block more then X outgoing recipients at a time ( useful to prevent spammers/bots abusing the service )
     if (count($mail) - $groupmails > $pref['max_recipients_per_msg']) {
         $this->smtperror("Cannot send to more than {$pref['max_recipients_per_msg']} users per email message.");
     }
     require_once 'Net/SMTP.php';
     $smtp = new Net_SMTP($pref['smtphost'], null, $_SERVER['HTTP_HOST']);
     //$smtp->setDebug(true);
     if ($smtp->connect(30) !== true) {
         if ($catch_smtp_error) {
             $this->smtperror("Error connecting to {$pref['smtphost']} - Check the hostname resolves, accepts incoming SMTP connections and is active.");
         } else {
             return false;
         }
     }
     // Check if we should use each account's username and password
     // for the SMTP
     if ($pref['smtp_per_account_auth']) {
         $pref['smtpauth_username'] = $atmail->auth->get_username();
         $pref['smtpauth_password'] = $atmail->auth->get_password();
     }
     // Optionally authenticate with the SMTP server
     if ($pref['smtpauth_username'] && $pref['smtpauth_password']) {
         if ($smtp->auth($pref['smtpauth_username'], $pref['smtpauth_password']) !== true) {
             if ($catch_smtp_error) {
                 $this->smtperror("Error authenticating to {$pref['smtphost']} - Check the SMTP authentication is correct");
             } else {
                 $this->smtp_error_msg = "Error authenticating to {$pref['smtphost']} - Check the SMTP authentication is correct";
                 return false;
             }
         }
     }
     $smtp->mailFrom($this->EmailFrom);
     $fails = array();
     //$smtp->setDebug(true);
     foreach ($mail as $v) {
         $res = $smtp->rcptTo($v);
         if (PEAR::isError($res)) {
             if ($catch_smtp_error) {
                 $output = $res->getMessage();
                 $this->smtperror("Could not send message to SMTP server. Check you have access to send messages via the server and that all To/CC/BCC addresses are valid\\nError: {$output}");
                 break;
             } else {
                 $fails[] = $v;
                 continue;
             }
         }
     }
     $res = $smtp->data($this->headers . "\r\n\r\n" . $this->body);
     if (PEAR::isError($res)) {
         if ($catch_smtp_error) {
             $this->smtperror("Message rejected by SMTP server. Check message content and attachments\\nServer Responded: " . $res->getMessage());
         } else {
             $this->smtp_error_msg = "Message rejected by SMTP server. Check message content and attachments\nServer Responded: " . $res->getMessage();
             return false;
         }
     } elseif ($pref['install_type'] == 'standalone') {
         // Only log sent msgs if running only as webmail client
         // as Exim already does this when in server mode
         foreach ($mail as $addr) {
             $addr = preg_replace('/\\s+/', '', $addr);
             $this->log->write_log("SendMail", "WebMail:{$_SERVER['REMOTE_ADDR']}:{$addr}");
         }
     }
     $smtp->disconnect();
     // Reset some fields back to the raw UTF8 copy, since it's sent to the browser
     $this->EmailSubject = $this->RawEmailSubject;
     return $fails;
 }
Example #15
0
 /**
  * Sends and e-mail using Net_SMTP.
  *
  * @param Email $email
  * @return string Error message, or null upon success.
  */
 public static function smtp(&$email)
 {
     /*
         if ( isset($GLOBALS['phpmail']) && $GLOBALS['phpmail'] )
         {
           $rfc = new \Mail_RFC822();
           $pureAddresses = $rfc->parseAddressList($email->to());
           foreach( $pureAddresses as $address )
           {
             $to = $address->mailbox. "@". $address->host;
             mail( $to, $email->subject(), $email->body(), $email->headers() );
           }
           return;
         }
     */
     Log::debug("Mailer: subject:[" . $email->subject() . "], from:[" . $email->from() . "], to:" . print_r($email->recipients(), true));
     if (!Config::$smtpHost) {
         $error = "Mailer: no SMTP host supplied";
         Log::debug($error);
         return $error;
     }
     if (!($smtp = new \Net_SMTP(Config::$smtpHost, Config::$smtpPort, $_SERVER['SERVER_NAME']))) {
         $error = "Mailer: unable to instantiate Net_SMTP object";
         Log::debug($error);
         return $error;
     }
     // $smtp->setDebug(true);
     $pear = new \PEAR();
     if ($pear->isError($e = $smtp->connect())) {
         $error = "Mailer: connect error: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     if (Config::$smtpUser && $pear->isError($e = $smtp->auth(Config::$smtpUser, Config::$smtpPass, Config::$smtpAuthType))) {
         $error = "Mailer: authentication error: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     $rfc = new \Mail_RFC822();
     $pureAddresses = $rfc->parseAddressList($email->from());
     $from = $pureAddresses[0]->mailbox . "@" . $pureAddresses[0]->host;
     if ($pear->isError($e = $smtp->mailFrom($from))) {
         $error = "Unable to set sender to [{$from}]: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     foreach ($email->recipients() as $toAddress) {
         $pureAddresses = $rfc->parseAddressList($toAddress);
         foreach ($pureAddresses as $address) {
             $to = $address->mailbox . "@" . $address->host;
             if ($pear->isError($e = $smtp->rcptTo($to))) {
                 $error = "Unable to set recipient to [{$to}]: " . $e->getMessage();
                 Log::debug($error);
                 return $error;
             }
         }
     }
     if ($pear->isError($e = $smtp->data($email->data()))) {
         $error = "Unable to set data: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     Log::debug("Mailer: sent: " . $smtp->_arguments[0]);
     $smtp->disconnect();
     return null;
 }
Example #16
0
 /**
  * Send a message.
  *
  * @param mixed $recipients  Either a comma-seperated list of recipients
  *                           (RFC822 compliant), or an array of
  *                           recipients, each RFC822 valid. This may
  *                           contain recipients not specified in the
  *                           headers, for Bcc:, resending messages, etc.
  * @param array $headers     The headers to send with the mail, in an
  *                           associative array, where the array key is the
  *                           header name (ie, 'Subject'), and the array
  *                           value is the header value (ie, 'test'). The
  *                           header produced from those values would be
  *                           'Subject: test'.
  *                           If the '_raw' key exists, the value of this
  *                           key will be used as the exact text for
  *                           sending the message.
  * @param mixed $body        The full text of the message body, including
  *                           any Mime parts, etc. Either a string or a
  *                           stream resource.
  *
  * @throws Horde_Mail_Exception
  */
 public function send($recipients, array $headers, $body)
 {
     /* If we don't already have an SMTP object, create one. */
     $this->getSMTPObject();
     $headers = $this->_sanitizeHeaders($headers);
     try {
         list($from, $textHeaders) = $this->prepareHeaders($headers);
     } catch (Horde_Mail_Exception $e) {
         $this->_smtp->rset();
         throw $e;
     }
     /* Since few MTAs are going to allow this header to be forged unless
      * it's in the MAIL FROM: exchange, we'll use Return-Path instead of
      * From: if it's set. */
     foreach (array_keys($headers) as $hdr) {
         if (strcasecmp($hdr, 'Return-Path') === 0) {
             $from = $headers[$hdr];
             break;
         }
     }
     if (!strlen($from)) {
         $this->_smtp->rset();
         throw new Horde_Mail_Exception('No From: address has been provided', self::ERROR_FROM);
     }
     $params = '';
     foreach ($this->_extparams as $key => $val) {
         $params .= ' ' . $key . (is_null($val) ? '' : '=' . $val);
     }
     $res = $this->_smtp->mailFrom($from, ltrim($params));
     if ($res instanceof PEAR_Error) {
         $this->_error("Failed to set sender: {$from}", $res, self::ERROR_SENDER);
     }
     try {
         $recipients = $this->parseRecipients($recipients);
     } catch (Horde_Mail_Exception $e) {
         $this->_smtp->rset();
         throw $e;
     }
     foreach ($recipients as $recipient) {
         $res = $this->_smtp->rcptTo($recipient);
         if ($res instanceof PEAR_Error) {
             $this->_error("Failed to add recipient: {$recipient}", $res, self::ERROR_RECIPIENT);
         }
     }
     /* Send the message's headers and the body as SMTP data. Net_SMTP does
      * the necessary EOL conversions. */
     $res = $this->_smtp->data($body, $textHeaders);
     list(, $args) = $this->_smtp->getResponse();
     if (preg_match("/Ok: queued as (.*)/", $args, $queued)) {
         $this->queuedAs = $queued[1];
     }
     /* We need the greeting; from it we can extract the authorative name
      * of the mail server we've really connected to. Ideal if we're
      * connecting to a round-robin of relay servers and need to track
      * which exact one took the email */
     $this->greeting = $this->_smtp->getGreeting();
     if ($res instanceof PEAR_Error) {
         $this->_error('Failed to send data', $res, self::ERROR_DATA);
     }
     /* If persistent connections are disabled, destroy our SMTP object. */
     if ($this->_params['persist']) {
         $this->disconnect();
     }
 }