示例#1
0
function sendEmail($recipient, $content, $subject = 'Notification', $includeStandardFooter = true)
{
    $subject = 'lanlist.org - ' . $subject;
    if (empty($content)) {
        throw new Exception('Cannot send a blank email');
    }
    $content = wordwrap($content);
    if ($includeStandardFooter) {
        $content .= "\n\n- lanlist.org";
    }
    ErrorHandler::getInstance()->beLazy();
    require_once 'Mail.php';
    require_once 'Mail/smtp.php';
    $host = 'ssl://smtp.gmail.com';
    $username = '******';
    $password = '******';
    $smtp = new Mail_smtp(array('host' => $host, 'port' => 465, 'auth' => true, 'username' => $username, 'password' => $password));
    $headers = array('From' => '"lanlist.org" <*****@*****.**>', 'To' => '<' . $recipient . '>', 'Subject' => $subject, 'Content-Type' => 'text/html');
    $smtp->send('<' . $recipient . '>', $headers, $content);
    ErrorHandler::getInstance()->beGreedy();
    Logger::messageDebug('Sending email to ' . $recipient . ', subject: ' . $subject);
    $sql = 'INSERT INTO email_log (subject, emailAddress, sent) VALUES (:subject, :emailAddress, now())';
    $stmt = DatabaseFactory::getInstance()->prepare($sql);
    $stmt->bindValue(':emailAddress', $recipient);
    $stmt->bindValue(':subject', $subject);
    $stmt->execute();
}
示例#2
0
 /**
  * Send mail using a PEAR mailer
  *
  * @param Mail_smtp $mailer
  * @param string $dest
  * @param string $headers
  * @param string $body
  *
  * @return Status
  */
 protected static function sendWithPear($mailer, $dest, $headers, $body)
 {
     $mailResult = $mailer->send($dest, $headers, $body);
     // Based on the result return an error string,
     if (PEAR::isError($mailResult)) {
         wfDebug("PEAR::Mail failed: " . $mailResult->getMessage() . "\n");
         return Status::newFatal('pear-mail-error', $mailResult->getMessage());
     } else {
         return Status::newGood();
     }
 }
示例#3
0
 /**
  * Sends and receives SOAP data.
  *
  * @access public
  *
  * @param string  Outgoing SOAP data.
  * @param array   Options.
  *
  * @return string|SOAP_Fault
  */
 function send($msg, $options = array())
 {
     $this->fault = null;
     $this->incoming_payload = '';
     $this->outgoing_payload = $msg;
     if (!$this->_validateUrl()) {
         return $this->fault;
     }
     if (!$options || !isset($options['from'])) {
         return $this->_raiseSoapFault('No From: address to send message with');
     }
     if (isset($options['host'])) {
         $this->host = $options['host'];
     }
     if (isset($options['port'])) {
         $this->port = $options['port'];
     }
     if (isset($options['auth'])) {
         $this->auth = $options['auth'];
     }
     if (isset($options['username'])) {
         $this->username = $options['username'];
     }
     if (isset($options['password'])) {
         $this->password = $options['password'];
     }
     $headers = array();
     $headers['From'] = $options['from'];
     $headers['X-Mailer'] = $this->_userAgent;
     $headers['MIME-Version'] = '1.0';
     $headers['Message-ID'] = md5(time()) . '.soap@' . $this->host;
     $headers['To'] = $this->urlparts['path'];
     if (isset($options['soapaction'])) {
         $headers['Soapaction'] = "\"{$options['soapaction']}\"";
     }
     if (isset($options['headers'])) {
         $headers = array_merge($headers, $options['headers']);
     }
     // If the content type is already set, we assume that MIME encoding is
     // already done.
     if (isset($headers['Content-Type'])) {
         $out = $msg;
     } else {
         // Do a simple inline MIME encoding.
         $headers['Content-Disposition'] = 'inline';
         $headers['Content-Type'] = "text/xml; charset=\"{$this->encoding}\"";
         if (isset($options['transfer-encoding'])) {
             if (strcasecmp($options['transfer-encoding'], 'quoted-printable') == 0) {
                 $headers['Content-Transfer-Encoding'] = $options['transfer-encoding'];
                 $out = $msg;
             } elseif (strcasecmp($options['transfer-encoding'], 'base64') == 0) {
                 $headers['Content-Transfer-Encoding'] = 'base64';
                 $out = chunk_split(base64_encode($msg), 76, "\n");
             } else {
                 return $this->_raiseSoapFault("Invalid Transfer Encoding: {$options['transfer-encoding']}");
             }
         } else {
             // Default to base64.
             $headers['Content-Transfer-Encoding'] = 'base64';
             $out = chunk_split(base64_encode($msg));
         }
     }
     $headers['Subject'] = isset($options['subject']) ? $options['subject'] : 'SOAP Message';
     foreach ($headers as $key => $value) {
         $header_text .= "{$key}: {$value}\n";
     }
     $this->outgoing_payload = $header_text . "\r\n" . $this->outgoing_payload;
     $mailer_params = array('host' => $this->host, 'port' => $this->port, 'username' => $this->username, 'password' => $this->password, 'auth' => $this->auth);
     $mailer = new Mail_smtp($mailer_params);
     $result = $mailer->send($this->urlparts['path'], $headers, $out);
     if (!PEAR::isError($result)) {
         $val = new SOAP_Value('Message-ID', 'string', $headers['Message-ID']);
     } else {
         $sval[] = new SOAP_Value('faultcode', 'QName', SOAP_BASE::SOAPENVPrefix() . ':Client');
         $sval[] = new SOAP_Value('faultstring', 'string', "couldn't send SMTP message to {$this->urlparts['path']}");
         $val = new SOAP_Value('Fault', 'Struct', $sval);
     }
     $methodValue = new SOAP_Value('Response', 'Struct', array($val));
     $this->incoming_payload = $this->makeEnvelope($methodValue, $this->headers, $this->encoding);
     return $this->incoming_payload;
 }
示例#4
0
文件: smtpraw.php 项目: roojs/pear
 function Mail_smtpraw($params)
 {
     parent::Mail_smtp($params);
 }
示例#5
0
 /**
  * Connect to the SMTP server by instantiating a Net_SMTP object.
  *
  * @return mixed Returns a reference to the Net_SMTP object on success, or
  *               a PEAR_Error containing a descriptive error message on
  *               failure.
  *
  * @since  1.2.0
  * @access public
  */
 function &getSMTPObject()
 {
     if (is_object($this->_smtp) !== false) {
         return $this->_smtp;
     }
     include_once 'include/Net/SMTP.php';
     $this->_smtp =& new Net_SMTP($this->host, $this->port, $this->localhost, $this->pipelining);
     /* If we still don't have an SMTP object at this point, fail. */
     if (is_object($this->_smtp) === false) {
         return Mail_smtp::raiseError('Failed to create a Net_SMTP object', PEAR_MAIL_SMTP_ERROR_CREATE);
     }
     /* Configure the SMTP connection. */
     if ($this->debug) {
         $this->_smtp->setDebug(true);
     }
     /* Attempt to connect to the configured SMTP server. */
     //if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) {
     if (($res = $this->_smtp->connect($this->timeout)) === false) {
         $error = $this->_error('Failed to connect to ' . $this->host . ':' . $this->port, $res);
         return Mail_smtp::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT);
     }
     /* 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))) {
         if (($res = $this->_smtp->auth($this->username, $this->password, $method)) === false) {
             $error = $this->_error("{$method} authentication failure", $res);
             $this->_smtp->rset();
             return Mail_smtp::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH);
         }
     }
     return $this->_smtp;
 }
示例#6
0
<?php

set_include_path("/usr/local/lib/php/");
include_once 'Mail.php';
include_once 'Mail/smtp.php';
# 发信人,用正确邮件地址替代
$from = '*****@*****.**';
# 收件人地址,用正确邮件地址替代
$to = array('*****@*****.**', '*****@*****.**');
# 邮件标题
$subject = 'SendCloud PHP Smtp Example';
# 邮件正文,html格式
$body = "<html><head></head><body>\n        <p>欢迎使用<a href='http://sendcloud.sohu.com'>SendCloud!</a></p>\n        </body></html>";
# smtp参数, 用正确api_user和api_key验证
$param = array('host' => 'smtpcloud.sohu.com', 'ip' => 25, 'auth' => true, 'username' => 'api_user', 'password' => 'api_key');
$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject, 'Content-Type' => 'text/html;charset=utf8');
function getMessageId($res)
{
    $list = explode('#', $res);
    return $list[1];
}
$mail = new Mail_smtp($param);
$res = $mail->send($to, $headers, $body);
$messageId = getMessageId($res);
echo $messageId;