protected function send($alternateRecipient = null) { $mime = new Mail_mime(array("head_charset" => "utf-8", "text_charset" => "utf-8", "html_charset" => "utf-8", 'eol' => "\n")); $mime->setTXTBody($this->txtBody); if ($this->htmlBody !== null) { $mime->setHTMLBody($this->htmlBody); } if (!empty($this->attachments)) { foreach ($this->attachments as $attachment) { $mime->addAttachment($attachment->File(), $attachment->Type()); } } $this->headers['To'] = $this->receipients; $this->headers['Sender'] = $this->headers['From']; $empfaenger = $this->receipients; if ($this->bcc !== null) { $this->receipients .= ($this->receipients > '' ? ',' : '') . $this->bcc; } //do not ever try to call these lines in reverse order $body = $mime->get(); $headers = $mime->headers($this->headers, true); if ($this->receipients > '') { if (!$GLOBALS['Settings']['OnServer']) { $this->receipients = '*****@*****.**'; } elseif ($alternateRecipient) { $this->receipients = $alternateRecipient; } $mail_queue = new Mail_Queue($GLOBALS['Settings']['MailQueue']['db_options'], $GLOBALS['Settings']['MailQueue']['mail_options']); $mail_queue->put($this->headers['From'], $this->receipients, $headers, $body, $this->delay); } return true; }
/** * 邮件发送 * @return boolean */ public function send_mail($recipient, $mailsubject, $mailbody) { apf_require_file("Swift.php"); Swift_ClassLoader::load("Swift_Connection_SMTP"); $message = new Swift_Message($mailsubject); $message->setFrom("安居客<*****@*****.**>"); $message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8")); $message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8")); foreach ($recipient as $re) { Mail_Queue::put('*****@*****.**', $re, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE); } return true; }
/** * 邮件发送 * @param recipient 邮件接收方email * @param mailsubject 邮件主题 * @param mailbody 邮件内容 * @return boolean */ private function send_mail($recipient, $mailsubject, $mailbody) { try { $message = new Swift_Message($mailsubject); $message->setFrom("安居客<" . $this->sender . ">"); $message->setTo($recipient); $message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8")); $message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8")); Mail_Queue::put($this->sender, $recipient, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE); return true; } catch (Exception $e) { return false; } }
protected function sentMail($mailSubject, $mailBody) { if ($this->mailSwitch == true && !empty($this->mailAddress)) { $mailto = $this->mailAddress; apf_require_file("Swift.php"); Swift_ClassLoader::load("Swift_Connection_SMTP"); $smtpuser = APF::get_instance()->get_config("SmtpUser"); $smtpemailto = $mailto; $message = new Swift_Message($mailSubject); $message->setFrom("安居客<" . $smtpuser . ">"); $message->setTo($smtpemailto); $message->attach(new Swift_Message_Part(strip_tags($mailBody), "text/plain", "base64", "utf-8")); $message->attach(new Swift_Message_Part($mailBody, "text/html", "base64", "utf-8")); foreach ($smtpemailto as $to) { if (!empty($to)) { @Mail_Queue::put($smtpuser, $to, $mailSubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE); } } } }
/** * 发送邮件 * @param $mailSubject 标题 * @param $mailBody 内容 * @param array $mailTo 接受人,数组 * @return bool */ public function sendMail($mailSubject, $mailBody, $mailTo = array()) { if (empty($mailSubject) || empty($mailBody) || empty($mailTo)) { return false; } apf_require_file("Swift.php"); Swift_ClassLoader::load("Swift_Connection_SMTP"); $smtpuser = APF::get_instance()->get_config("SmtpUser"); $smtpemailto = $mailTo; $message = new Swift_Message($mailSubject); $message->setFrom("安居客<" . $smtpuser . ">"); $message->setTo($smtpemailto); $message->attach(new Swift_Message_Part(strip_tags($mailBody), "text/plain", "base64", "utf-8")); $message->attach(new Swift_Message_Part($mailBody, "text/html", "base64", "utf-8")); foreach ($smtpemailto as $to) { if (!empty($to)) { @Mail_Queue::put($smtpuser, $to, $mailSubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE); } } return true; }
function put_mail_queue($address, $subject, $body, $is_receive_mail = true, $from = ADMIN_EMAIL) { if (!$is_receive_mail || !db_common_is_mailaddress($address)) { return false; } // 改行コード $cr = "\r"; $lf = "\n"; $crlf = "\r\n"; // header $headers['MIME-Version'] = "1.0"; $headers['Content-Type'] = "text/plain; charset=iso-2022-jp"; $headers['From'] = $from; $headers['To'] = $address; // 半角カナを全角カナに変換 if (MAIL_HAN2ZEN) { $subject = mb_convert_kana($subject, "KV"); $body = mb_convert_kana($body, "KV"); } // subject (改行コードを含んではならない) $subject = str_replace(array($cr, $lf), "", $subject); $subject = mb_convert_encoding($subject, "JIS"); $headers['Subject'] = '=?ISO-2022-JP?B?' . base64_encode($subject) . '?='; // body (LF) if (MAIL_WRAP_WIDTH) { $body = t_wordwrap($body, MAIL_WRAP_WIDTH); } $body = mb_convert_encoding($body, "JIS"); $body = str_replace($cr, $lf, str_replace($crlf, $lf, $body)); include_once 'Mail/Queue.php'; $db_opt = array("type" => "db", "dsn" => $GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn'], "mail_table" => "mail_queue"); $mail_opt = array("driver" => "mail"); if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] === 'pgsql') { $db_opt['sequence'] = 'mail_queue_seq_id'; } $mail_mime = new Mail_mime(); $mail_mime->setTXTBody($body); $body = $mail_mime->get(array("text_charset" => "ISO-2022-JP")); $body = addslashes($body); $headers = $mail_mime->headers($headers); if (MAIL_SET_ENVFROM) { if (MAIL_ENVFROM) { $f = MAIL_ENVFROM; } else { $f = ADMIN_EMAIL; } $params = '-f' . escapeshellcmd($f); $mail_opt['param'] = $params; $mail_queue = new Mail_Queue($db_opt, $mail_opt); return $mail_queue->put($from, $address, $headers, $body); } else { $mail_queue = new Mail_Queue($db_opt, $mail_opt); return $mail_queue->put($from, $address, $headers, $body); } }
/** * Положить письмо в очередь * * @param string $recipient * @param string $from * @param string $subject * @param string $message * @param string HTML-сообщение * * Чтобы отправить сообщение в формате HTML, нужно указать параметр html_message. * При этом параметр message должен содержать сообщение в plain text или может быть пустым * * Чтобы отправить plain text, параметр html_message нужно оставить пустым. */ function nc_mail2queue($recipient, $from, $subject, $message, $html_message = "", $attachment_type = "") { require_once "Mail/Queue.php"; $db_options = array('type' => 'ezsql', 'mail_table' => 'Mail_Queue'); $mail_options = array('driver' => 'mail'); $mail_queue = new Mail_Queue($db_options, $mail_options); $hdrs = array('From' => $from, 'Subject' => nc_base64_encode_header($subject)); $mime = new Mail_mime("\n"); if ($attachment_type) { $nc_core = nc_Core::get_object(); $db = $nc_core->db; $type_escaped = $db->escape($attachment_type); $sql = "SELECT `Filename`, `Path`, `Content_Type`, `Extension` FROM `Mail_Attachment` WHERE `Type` = '{$type_escaped}'"; $attachments = (array) $db->get_results($sql, ARRAY_A); while (preg_match('/\\%FILE_([-_a-z0-9]+)/i', $html_message, $match)) { $filename = $match[1]; $file = false; foreach ($attachments as $index => $attachment) { if (strtolower($attachment['Filename']) == strtolower($filename)) { $file = $attachment; unset($attachments[$index]); break; } } $replace = ''; if ($file) { $absolute_path = $nc_core->DOCUMENT_ROOT . $file['Path']; $replace = 'file_' . $filename . '.' . $file['Extension']; $mime->addHTMLImage(@file_get_contents($absolute_path), $file['Content_Type'], $replace, false); } $html_message = preg_replace('/\\%FILE_' . preg_quote($filename) . '/', $replace, $html_message); } foreach ($attachments as $attachment) { $absolute_path = $nc_core->DOCUMENT_ROOT . $attachment['Path']; $mime->addAttachment($absolute_path, $attachment['Content_Type'], $attachment['Filename'] . '.' . $attachment['Extension']); } } if ($message) { $mime->setTXTBody($message); } if ($html_message) { $mime->setHTMLBody($html_message); } $body = $mime->get(array('text_encoding' => '8bit', 'html_charset' => MAIN_EMAIL_ENCODING, 'text_charset' => MAIN_EMAIL_ENCODING, 'head_charset' => MAIN_EMAIL_ENCODING)); $hdrs = $mime->headers($hdrs); $mail_queue->put($from, $recipient, $hdrs, $body); }
private function sendMail() { switch ($this->_dealType) { case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_OFFICE_RENT: $subject = '金铺【铺租】房源过期、违规,套餐关系修复'; break; case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_OFFICE_SALE: $subject = '金铺【铺售】房源过期、违规,套餐关系修复'; break; case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_SHOP_RENT: $subject = '金铺【楼售】房源过期、违规,套餐关系修复'; break; case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_SHOP_SALE: $subject = '金铺【楼租】房源过期、违规,套餐关系修复'; break; default: $subject = '金铺房源删除,套餐关系修复'; } $content = file_get_contents($this->_email); foreach ($this->_recipient as $recipient) { Mail_Queue::put('*****@*****.**', $recipient, $subject, $content, Const_Mail::TYPE_PLAIN, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE); } }
function send_newsletter($newsletter_id) { $sm = vivvo_lite_site::get_instance(); $db = $sm->get_db(); if ($sm->user) { if ($sm->user->is_admin()) { $newsletter_list = new newsletter_list(); $newsletter = $newsletter_list->get_newsletter_by_id($newsletter_id); if ($newsletter !== false) { if ($newsletter->test == 1) { $to = $newsletter->test_email; if ($newsletter->vte_template == '1') { $body_template = new template(); $template_sting = xml_template_node::xmlentities_decode($newsletter->body); $body_template->set_string_template($template_sting); $body = $body_template->get_output() . "\n\n"; } else { $body = xml_template_node::xmlentities_decode($newsletter->body); } $unsubscribe_url = VIVVO_PROXY_URL . 'newsletter/index.html?&action=newsletter&cmd=subscriberUnSubscribe&dack=' . md5('test'); if (!preg_match('/^[^:]+:/', $unsubscribe_url)) { $unsubscribe_url = VIVVO_URL . $unsubscribe_url; } $body = $body . "\n\n\n" . VIVVO_PLUGIN_NEWSLETTER_UNSUBSCRIBE_TEXT . "\n" . $unsubscribe_url; $from = VIVVO_ADMINISTRATORS_EMAIL; $search = array('(', ')', '<', '>', '@', ';', ':', '\\', '"', '.', '[', ']'); $replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); $from_name = str_replace($search, $replace, VIVVO_WEBSITE_TITLE); $from_name = "=?UTF-8?B?" . base64_encode($from_name) . "?="; $from_params = !empty($from_name) ? '"' . $from_name . '" <' . $from . '>' : '<' . $from . '>'; $headers['From'] = $from_params; $recipients = array(); $recipients[] = $to; $subject = "=?UTF-8?B?" . base64_encode($newsletter->subject) . "?="; $headers['Subject'] = $subject; $headers['Content-Type'] = "text/plain; charset=UTF-8;"; if (VIVVO_EMAIL_SMTP_PHP == 1) { $mail_object = new Mail(); $mail_object->send($to, $headers, $body); } else { $mail_options['driver'] = 'smtp'; $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST; $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT; $mail_options['localhost'] = 'localhost'; if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') { $mail_options['auth'] = true; $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME; $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD; } else { $mail_options['auth'] = false; $mail_options['username'] = ''; $mail_options['password'] = ''; } $mail_object =& Mail::factory('smtp', $mail_options); $mail_object->send($to, $headers, $body); } } else { $container_options = array('type' => 'mdb2', 'dsn' => VIVVO_DB_TYPE . '://' . VIVVO_DB_USER . ':' . VIVVO_DB_PASSWORD . '@' . VIVVO_DB_HOST . '/' . VIVVO_DB_DATABASE, 'mail_table' => VIVVO_DB_PREFIX . 'mail_queue'); $mail_options['driver'] = 'smtp'; $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST; $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT; $mail_options['localhost'] = 'localhost'; if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') { $mail_options['auth'] = true; $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME; $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD; } else { $mail_options['auth'] = false; $mail_options['username'] = ''; $mail_options['password'] = ''; } $mail_queue = new Mail_Queue($container_options, $mail_options); $from = VIVVO_ADMINISTRATORS_EMAIL; $search = array('(', ')', '<', '>', '@', ';', ':', '\\', '"', '.', '[', ']'); $replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); $from_name = str_replace($search, $replace, VIVVO_WEBSITE_TITLE); $from_name = "=?UTF-8?B?" . base64_encode($from_name) . "?="; $from_params = !empty($from_name) ? '"' . $from_name . '" <' . $from . '>' : '<' . $from . '>'; if ($newsletter->vte_template == '1') { $body_template = new template(); $template_sting = xml_template_node::xmlentities_decode($newsletter->body); $body_template->set_string_template($template_sting); $body = $body_template->get_output() . "\n\n"; } else { $body = xml_template_node::xmlentities_decode($newsletter->body); } $groups = explode(',', $newsletter->groups); foreach ($groups as $key) { if ($key == -1) { $res =& $db->query('SELECT email, ip, time FROM ' . VIVVO_DB_PREFIX . 'maillist WHERE `confirm` = \'1\''); if (!is_a($res, 'mdb2_error')) { while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { $subject = "=?UTF-8?B?" . base64_encode($newsletter->subject) . "?="; $recipient = $row['email']; $hdrs = array('From' => $from_params, 'To' => $recipient, 'Subject' => $subject, 'Content-Type' => "text/plain; charset=UTF-8;"); $body_all = $body . "\n\n\n" . VIVVO_PLUGIN_NEWSLETTER_UNSUBSCRIBE_TEXT . "\n" . VIVVO_URL . 'newsletter/index.html?action=newsletter&cmd=subscriberUnSubscribe&dack=' . md5($row['ip'] . $row['time'] . $row['email']); $mail_queue->put($from, $recipient, $hdrs, $body_all); } } } elseif ($key >= 0) { $res = $db->query('SELECT email_address, userid, created FROM ' . VIVVO_DB_PREFIX . 'users as u INNER JOIN ' . VIVVO_DB_PREFIX . 'group_user as gu ON gu.user_id=u.userid WHERE gu.group_id = \'' . $key . '\' and `subscriber` = \'1\''); if (!is_a($res, 'mdb2_error')) { while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { $recipient = $row['email_address']; $subject = "=?UTF-8?B?" . base64_encode($newsletter->subject) . "?="; $hdrs = array('From' => $from_params, 'To' => $recipient, 'Subject' => $subject, 'Content-Type' => "text/plain; charset=UTF-8;"); $unsubscribe_url = VIVVO_PROXY_URL . 'newsletter/index.html?action=newsletter&cmd=userUnSubscribe&dack=' . md5($row['email_address'] . $row['userid'] . $row['created']); if (!preg_match('/^[^:]+:/', $unsubscribe_url)) { $unsubscribe_url = VIVVO_URL . $unsubscribe_url; } $body_all = $body . "\n\n\n" . VIVVO_PLUGIN_NEWSLETTER_UNSUBSCRIBE_TEXT . "\n" . $unsubscribe_url; $mail_queue->put($from, $recipient, $hdrs, $body_all); } } } } } return true; } else { $this->set_error_code(10225); return false; } } else { $this->set_error_code(10226); return false; } } else { $this->set_error_code(10227); return false; } }