Posted by Dimitris Tue 6th Mar 2007 13:32 - Syntax is Scheme - 20 views
Download | New Post | Modify | Hide line numbers
  1.    
  2. //pear sned function
  3. function send($recipients, $headers, $body)
  4.     {
  5.         include_once 'Net/SMTP.php';
  6.  
  7.  
  8.         /* If we don't already have an SMTP object, create one. */
  9.         if (is_object($this->_smtp) === false) {
  10.             $this->_smtp =& new Net_SMTP($this->host, $this->port,
  11.                                          $this->localhost);
  12.  
  13.             /* If we still don't have an SMTP object at this point, fail. */
  14.             if (is_object($this->_smtp) === false) {
  15.                 return PEAR::raiseError('Failed to create a Net_SMTP object',
  16.                                         PEAR_MAIL_SMTP_ERROR_CREATE);
  17.             }
  18.  
  19.             /* Configure the SMTP connection. */
  20.             if ($this->debug) {
  21.                 $this->_smtp->setDebug(true);
  22.             }
  23.             $id = Gtk::timeout_add(200,'progress_bar_activity');
  24.             /* Attempt to connect to the configured SMTP server. */
  25.             if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) {
  26.                 $error = $this->_error('Failed to connect to ' .
  27.                                        $this->host . ':' . $this->port,
  28.                                        $res);
  29.                 return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT);
  30.             }
  31.             echo '2';
  32.             /* Attempt to authenticate if authentication has been enabled. */
  33.             if ($this->auth) {
  34.                 $method = is_string($this->auth) ? $this->auth : '';
  35.  
  36.                 if (PEAR::isError($res = $this->_smtp->auth($this->username,
  37.                                                             $this->password,
  38.                                                             $method))) {
  39.                     $error = $this->_error("$method authentication failure",
  40.                                            $res);
  41.                     $this->_smtp->rset();
  42.                     return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH);
  43.                 }
  44.             }
  45.         }
  46.         $this->_sanitizeHeaders($headers);
  47.         $headerElements = $this->prepareHeaders($headers);
  48.         if (PEAR::isError($headerElements)) {
  49.             $this->_smtp->rset();
  50.             return $headerElements;
  51.         }
  52.         list($from, $textHeaders) = $headerElements;
  53.         /* Since few MTAs are going to allow this header to be forged
  54.          * unless it's in the MAIL FROM: exchange, we'll use
  55.          * Return-Path instead of From: if it's set. */
  56.         if (!empty($headers['Return-Path'])) {
  57.             $from = $headers['Return-Path'];
  58.         }
  59.         if (!isset($from)) {
  60.             $this->_smtp->rset();
  61.             return PEAR::raiseError('No From: address has been provided',
  62.                                     PEAR_MAIL_SMTP_ERROR_FROM);
  63.         }
  64.         $args['verp'] = $this->verp;
  65.         if (PEAR::isError($res = $this->_smtp->mailFrom($from, $args))) {
  66.             $error = $this->_error("Failed to set sender: $from", $res);
  67.             $this->_smtp->rset();
  68.             return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_SENDER);
  69.         }
  70.                     $recipients = $this->parseRecipients($recipients);
  71.         if (PEAR::isError($recipients)) {
  72.             $this->_smtp->rset();
  73.             return $recipients;
  74.         }
  75.         foreach ($recipients as $recipient) {
  76.             if (PEAR::isError($res = $this->_smtp->rcptTo($recipient))) {
  77.                 $error = $this->_error("Failed to add recipient: $recipient",
  78.                                        $res);
  79.                 $this->_smtp->rset();
  80.                 return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT);
  81.             }
  82.         }
  83.         /* Send the message's headers and the body as SMTP data. */
  84.         if (PEAR::isError($res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body))) {
  85.             $error = $this->_error('Failed to send data', $res);
  86.             $this->_smtp->rset();
  87.             return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA);
  88.         }
  89.         /* If persistent connections are disabled, destroy our SMTP object. */
  90.         if ($this->persist === false) {
  91.             $this->disconnect();
  92.         }
  93.         Gtk::timeout_remove($id);
  94.         return true;
  95.     }
  96.  
  97. //progress bar function
  98.  //function progress_bar activity
  99.   function progress_bar_activity() {
  100.    global $progress_bar;
  101.    $progress_bar->pulse();
  102.    return true;
  103.   }
  104.  
  105.  
  106.  
  107.  
  108.  

PermaLink to this entry https://pastebin.co.uk/11458
Posted by Dimitris Tue 6th Mar 2007 13:32 - Syntax is Scheme - 20 views
Download | New Post | Modify | Hide line numbers

 

Comments: 0