Posted by Dimitris Tue 6th Mar 2007 13:32 - Syntax is Scheme - 21 views
Download | New Post | Modify | Show line numbers
Download | New Post | Modify | Show line numbers
//pear sned function
function send($recipients, $headers, $body)
{
include_once 'Net/SMTP.php';
/* If we don't already have an SMTP object, create one. */
if (is_object($this->_smtp) === false) {
$this->_smtp =& new Net_SMTP($this->host, $this->port,
$this->localhost);
/* If we still don't have an SMTP object at this point, fail. */
if (is_object($this->_smtp) === false) {
return PEAR::raiseError('Failed to create a Net_SMTP object',
PEAR_MAIL_SMTP_ERROR_CREATE);
}
/* Configure the SMTP connection. */
if ($this->debug) {
$this->_smtp->setDebug(true);
}
$id = Gtk::timeout_add(200,'progress_bar_activity');
/* Attempt to connect to the configured SMTP server. */
if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) {
$error = $this->_error('Failed to connect to ' .
$this->host . ':' . $this->port,
$res);
return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT);
}
echo '2';
/* Attempt to authenticate if authentication has been enabled. */
if ($this->auth) {
$method = is_string($this->auth) ? $this->auth : '';
if (PEAR::isError($res = $this->_smtp->auth($this->username,
$this->password,
$method))) {
$error = $this->_error("$method authentication failure",
$res);
$this->_smtp->rset();
return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH);
}
}
}
$this->_sanitizeHeaders($headers);
$headerElements = $this->prepareHeaders($headers);
if (PEAR::isError($headerElements)) {
$this->_smtp->rset();
return $headerElements;
}
list($from, $textHeaders) = $headerElements;
/* 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)) {
$this->_smtp->rset();
return PEAR::raiseError('No From: address has been provided',
PEAR_MAIL_SMTP_ERROR_FROM);
}
$args['verp'] = $this->verp;
if (PEAR::isError($res = $this->_smtp->mailFrom($from, $args))) {
$error = $this->_error("Failed to set sender: $from", $res);
$this->_smtp->rset();
return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_SENDER);
}
$recipients = $this->parseRecipients($recipients);
if (PEAR::isError($recipients)) {
$this->_smtp->rset();
return $recipients;
}
foreach ($recipients as $recipient) {
if (PEAR::isError($res = $this->_smtp->rcptTo($recipient))) {
$error = $this->_error("Failed to add recipient: $recipient",
$res);
$this->_smtp->rset();
return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT);
}
}
/* Send the message's headers and the body as SMTP data. */
if (PEAR::isError($res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body))) {
$error = $this->_error('Failed to send data', $res);
$this->_smtp->rset();
return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA);
}
/* If persistent connections are disabled, destroy our SMTP object. */
if ($this->persist === false) {
$this->disconnect();
}
Gtk::timeout_remove($id);
return true;
}
//progress bar function
//function progress_bar activity
function progress_bar_activity() {
global $progress_bar;
$progress_bar->pulse();
return true;
}
PermaLink to this entry https://pastebin.co.uk/11458
Posted by Dimitris Tue 6th Mar 2007 13:32 - Syntax is Scheme - 21 views
Download | New Post | Modify | Show line numbers
Download | New Post | Modify | Show line numbers
Comments: 0