예제 #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
<?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;