function my_inet_ntop($ip) { if (strlen($ip) == 4) { // ipv4 list(, $ip) = unpack('N', $ip); $ip = long2ip($ip); } elseif (strlen($ip) == 16) { // ipv6 $ip = bin2hex($ip); $ip = substr(chunk_split($ip, 4, ':'), 0, -1); $ip = explode(':', $ip); $res = ''; foreach ($ip as $seg) { while ($seg[0] == '0') { $seg = substr($seg, 1); } if ($seg != '') { $res .= ($res == '' ? '' : ':') . $seg; } else { if (strpos($res, '::') === false) { if (substr($res, -1) == ':') { continue; } $res .= ':'; continue; } $res .= ($res == '' ? '' : ':') . '0'; } } $ip = $res; } return $ip; }
function send_email($from, $to, $subject, $msg, $attachment) { $headers = "MIME-Version: 1.0\r\n" . $from; $rand = md5(time()); $headers .= "Content-Type: multipart/mixed; boundary=\"" . $rand . "\"\r\n\r\n"; $headers .= "--" . $rand . "\r\n"; $headers .= "Content-Type: text/html; charset=\"UTF-8\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n"; $headers .= $msg . "\r\n\r\n"; if (count($attachment) > 0) { foreach ($attachment as $file) { if (is_file($file)) { $content = chunk_split(base64_encode(read_file($file))); $headers .= "--" . $rand . "\r\n"; $headers .= "Content-Type: application/octet-stream; name=\"" . basename($file) . "\"\r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "Content-Disposition: attachment\r\n\r\n"; $headers .= $content . "\r\n\r\n"; } } } $headers .= "--" . $rand . "--\r\n"; if (@mail($to, $subject, "", $headers)) { return true; } return false; }
function insertKiiconnect() { global $databaseKiiconnect; $data = json_decode(stripslashes($_POST["data"])); $update["nombre"] = MySQL::SQLValue($data->nombre); $update["tag"] = MySQL::SQLValue($data->tag); $update["descripcion"] = MySQL::SQLValue($data->descripcion); $update["icono"] = MySQL::SQLValue($data->icono); $update["link"] = MySQL::SQLValue($data->link); $update["orden"] = MySQL::SQLValue($data->orden); $update["id_categoria"] = MySQL::SQLValue($data->id_categoria); $update["activo"] = MySQL::SQLValue($data->activo, MySQL::SQLVALUE_NUMBER); $databaseKiiconnect->InsertRow("kiiconnect_setting", $update); echo json_encode(array("success" => $databaseKiiconnect->ErrorNumber() == 0, "msg" => $databaseKiiconnect->ErrorNumber() == 0 ? "Parametro insertado exitosamente" : $databaseKiiconnect->ErrorNumber(), "data" => array(array("id" => $databaseKiiconnect->GetLastInsertID(), "nombre" => $data->nombre, "tag" => $data->tag, "descripcion" => $data->descripcion, "icono" => $data->icono, "link" => $data->link, "orden" => $data->orden, "id_categoria" => $data->id_categoria, "activo" => $data->activo)))); //inserto como blob la imagen $file = __DIR__ . '/../../../../' . $data->icono; if ($fp = fopen($file, "rb", 0)) { $picture = fread($fp, filesize($file)); fclose($fp); // base64 encode the binary data, then break it // into chunks according to RFC 2045 semantics $base64 = chunk_split(base64_encode($picture)); $tag = 'data:image/png;base64,' . $base64; } $lastId = $databaseKiiconnect->GetLastInsertID(); $databaseKiiconnect->Query("update kiiconnect_setting set file='{$tag}' where `id`='{$lastId}'"); }
function convert2vcf($data) { // //mapping uebimiau key to vcf key // $ldap_key = array("name" => "FN", "email" => "EMAIL;PREF;INTERNET", "street" => "ADR;WORK", "work" => "TITLE"); $ldapfile = "BEGIN:VCARD\r\nVERSION:2.1\r\n"; foreach ($data as $key => $value) { if ($key != "city" and $key != "state") { $testo = $key == "street" ? ";;" . $data["street"] . ";" . $data["city"] . ";;;" . $data["state"] : $value; if (ereg("[@,\r,\\(,\\),;,:]", $value)) { $testo = urlencode($testo); $testo = ereg_replace("\\+", " ", $testo); $testo = ereg_replace("%", "=", $testo); $testo = chunk_split($testo, 76, "=\r\n"); $testo = substr($testo, 0, strlen($testo) - 3); $ldapfile .= $ldap_key[$key] . ";ENCODING=QUOTED-PRINTABLE:{$testo}\r\n"; } else { $ldapfile .= $ldap_key[$key] . ":{$testo}\r\n"; } } } $ldapfile .= "REV:" . date("Ymd\\This", time()) . "\r\n"; $ldapfile .= "END:VCARD"; return $ldapfile; }
function send_mail($to, $thm, $html, $path) { $fp = fopen($path, "r"); if (!$fp) { print "Файл {$path} не может быть прочитан"; exit; } $file = fread($fp, filesize($path)); fclose($fp); $boundary = "--" . md5(uniqid(time())); // генерируем разделитель $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\n"; $multipart .= "--{$boundary}\n"; $kod = 'utf-8'; // или $kod = 'windows-1251'; $multipart .= "Content-Type: text/html; charset={$kod}\n"; $multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n"; $multipart .= "{$html}\n\n"; $message_part = "--{$boundary}\n"; $message_part .= "Content-Type: application/octet-stream\n"; $message_part .= "Content-Transfer-Encoding: base64\n"; $message_part .= "Content-Disposition: attachment; filename = \"" . $path . "\"\n\n"; $message_part .= chunk_split(base64_encode($file)) . "\n"; $multipart .= $message_part . "--{$boundary}--\n"; if (!mail($to, $thm, $multipart, $headers)) { exit("К сожалению, письмо не отправлено"); } }
function enc_header($str, $charset = 'utf-8', $encoding = 'quoted-printable') { $enc = false; if ($encoding == 'quoted-printable') { if (!$this->is_printable($str)) { $enc = $this->qpencode($str, $this->_hchunklen, $this->_crlf); $enc = str_replace('?', '=3F', $enc); } } elseif ($encoding == 'base64') { $enc = chunk_split(base64_encode($str), $this->_hchunklen, $this->_crlf); } if ($enc) { $res = array(); $arr = explode($this->_crlf, $enc); $chr = $encoding == 'base64' ? 'B' : 'Q'; foreach ($arr as $val) { if ($val != '') { $res[] = '=?' . $charset . '?' . $chr . '?' . $val . '?='; } } return implode($this->_crlf . "\t", $res); } else { return $str; } }
public function displayOptions($options) { echo 'Options list:' . PHP_EOL; $maxShortLength = 0; $maxLongLength = 0; $hasRequired = false; foreach ($options as $option) { if (($shortLength = strlen($option['short'])) > $maxShortLength) { $maxShortLength = $shortLength; } if (($longLength = strlen($option['long'])) > $maxLongLength) { $maxLongLength = $longLength; } $hasRequired = $hasRequired || $option['required']; } foreach ($options as $option) { $line = $option['short'] ? '-' . $option['short'] . str_repeat(' ', $maxShortLength + self::SPACE_LENGTH - strlen($option['short'])) : str_repeat(' ', $maxShortLength + 1 + self::SPACE_LENGTH); $line .= $option['long'] ? '--' . $option['long'] . str_repeat(' ', $maxLongLength + self::SPACE_LENGTH - strlen($option['long'])) : str_repeat(' ', $maxLongLength + 2 + self::SPACE_LENGTH); $descrLength = strlen($option['description']); $lineLength = strlen($line); $leadingSpaces = str_repeat(' ', $maxShortLength + $maxLongLength + 3 + self::SPACE_LENGTH * 2); if ($hasRequired) { $line .= ($option['required'] ? '!' : ' ') . str_repeat(' ', self::SPACE_LENGTH); $leadingSpaces .= str_repeat(' ', 1 + self::SPACE_LENGTH); } $line .= $lineLength < self::MAX_STR_LENGTH && self::MAX_STR_LENGTH < $descrLength + $lineLength ? rtrim(chunk_split($option['description'], self::MAX_STR_LENGTH - $lineLength, PHP_EOL . $leadingSpaces)) : $option['description']; echo $line . PHP_EOL; } if ($hasRequired) { echo PHP_EOL . '! - is for required options' . PHP_EOL; } }
function sendmail() { global $curtime; global $backupfile; global $archname; $text = "整站文件备份" . $backupfile; $subject = $backupfile; $from = '*****@*****.**'; $to = '*****@*****.**'; $file = $archname; $boundary = uniqid(""); $headers = "From:{$from}\r\n"; $headers .= "Content-type:multipart/mixed; boundary= {$boundary}\r\n"; $mimeType = "application/x-bzip2"; $fileName = $backupfile; $fp = fopen($file, "r"); $read = fread($fp, filesize($file)); $read = base64_encode($read); $read = chunk_split($read); $body = "--{$boundary}\nContent-type:text/plain; charset=utf-8\nContent-transfer-encoding: 8bit\n{$text}\n文件:{$backupfile}\n备份日期:{$curtime}\n--{$boundary}\nContent-type: {$mimeType}; name={$fileName}\nContent-disposition: attachment; filename={$fileName}\nContent-transfer-encoding: base64\n{$read}\n--{$boundary}--"; if (mail($to, $subject, $body, $headers)) { print "OK! Now the mail from {$from} ---to--- {$to} has been send<br>"; } else { print "fail to send mail <br>"; } }
/** * Send email an email with attachements * @param $files - array of files to send * ex: array( * "my_image.png" => array( * "path" => "/home/datawrapper/my_image.png", * "format" => "image/png" * ) * ) * */ function dw_send_mail_attachment($to, $from, $subject, $body, $files) { $random_hash = md5(date('r', time())); // $random_hash = md5(date('r', time())); $random_hash = '-----=' . md5(uniqid(mt_rand())); // headers $headers = 'From: ' . $from . "\n"; // $headers .= 'Return-Path: <'.$email_reply.'>'."\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-Type: multipart/mixed; boundary="' . $random_hash . '"'; // message $message = 'This is a multi-part message in MIME format.' . "\n\n"; $message .= '--' . $random_hash . "\n"; $message .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n"; $message .= 'Content-Transfer-Encoding: 8bit' . "\n\n"; $message .= $body . "\n\n"; // attached files foreach ($files as $fn => $file) { $path = $file["path"]; $format = $file["format"]; $attachment = chunk_split(base64_encode(file_get_contents($path))); $message .= '--' . $random_hash . "\n"; $message .= 'Content-Type: ' . $format . '; name="' . $fn . '"' . "\n"; $message .= 'Content-Transfer-Encoding: base64' . "\n"; $message .= 'Content-Disposition:attachement; filename="' . $fn . '"' . "\n\n"; $message .= $attachment . "\n"; } DatawrapperHooks::execute(DatawrapperHooks::SEND_EMAIL, $to, $subject, $message, $headers); }
/** * send * 必有方法,发送时调用 * * config参数为getOptions取得的所有项的配置结果 * * @param mixed $to * @param mixed $message * @param mixed $config * @access public * @return void */ function send($to, $subject, $body, $config) { $this->Sender = $config['usermail']; $this->Subject = $this->inlineCode($subject); if (constant("ECAE_MODE")) { // 保留原始的subject和body $config['subject'] = $subject; $config['body'] = $body; } $header = array('Return-path' => '<' . $config['usermail'] . '>', 'Date' => date('r'), 'From' => $this->inlineCode($config['shopname']) . '<' . $config['usermail'] . '>', 'MIME-Version' => '1.0', 'Subject' => $this->Subject, 'To' => $to, 'Content-Type' => 'text/html; charset=UTF-8; format=flowed', 'Content-Transfer-Encoding' => 'base64'); $config['sendway'] = $config['sendway'] ? $config['sendway'] : 'smtp'; if ($config['sendway'] == 'mail') { unset($header['Subject']); unset($header['To']); } $body = chunk_split(base64_encode($body)); $header = $this->buildHeader($header); switch ($config['sendway']) { case "sendmail": $result = $this->SendmailSend($to, $header, $body); break; case "mail": $result = $this->MailSend($to, $header, $body); break; case "smtp": $result = $this->SmtpSend($to, $header, $body, $config); break; default: // trigger_error('mailer_not_supported',E_ERROR); $result = false; break; } return $result; }
/** * Escapes the inserted value for LDAP. * * @param string $value * @param string $ignore * @param int $flags * * @return string */ protected static function escapeManual($value, $ignore = '', $flags = 0) { // If a flag was supplied, we'll send the value off // to be escaped using the PHP flag values // and return the result. if ($flags) { return static::escapeManualWithFlags($value, $ignore, $flags); } // Convert ignore string into an array. $ignores = static::ignoreStrToArray($ignore); // Convert the value to a hex string. $hex = bin2hex($value); // Separate the string, with the hex length of 2, and // place a backslash on the end of each section. $value = chunk_split($hex, 2, '\\'); // We'll append a backslash at the front of the string // and remove the ending backslash of the string. $value = '\\' . substr($value, 0, -1); // Go through each character to ignore. foreach ($ignores as $charToIgnore) { // Convert the character to ignore to a hex. $hexed = bin2hex($charToIgnore); // Replace the hexed variant with the original character. $value = str_replace('\\' . $hexed, $charToIgnore, $value); } // Finally we can return the escaped value. return $value; }
/** * @param $in_str * @param $charset * @return string */ function encode_headers($in_str, $charset) { $out_str = $in_str; if ($out_str && $charset) { // define start delimimter, end delimiter and spacer $end = "?="; $start = "=?" . $charset . "?b?"; $spacer = $end . "\r\n" . $start; // determine length of encoded text within chunks // and ensure length is even $length = 71 - strlen($spacer); // no idea why 71 but 75 didn't work $length = floor($length / 2) * 2; // encode the string and split it into chunks // with spacers after each chunk $out_str = base64_encode($out_str); $out_str = chunk_split($out_str, $length, $spacer); // remove trailing spacer and // add start and end delimiters $spacer = preg_quote($spacer); $out_str = preg_replace("/" . $spacer . "\$/", "", $out_str); $out_str = $start . $out_str . $end; } return $out_str; }
static function SendMail($from, $to, $subject, $message, $options = null, $bcc = array()) { global $INI; $from = "{$INI['system']['sitename']} <{$from}>"; if (!isset($options['subjectenc'])) { $options['subjectenc'] = 'GBK'; } if (!isset($options['encoding'])) { $options['encoding'] = 'UTF-8'; } if (!isset($options['contentType'])) { $options['contentType'] = 'text/plain'; } if ('UTF-8' != $options['encoding']) { $message = mb_convert_encoding($message, $options['encoding'], 'UTF-8'); } $message = chunk_split(base64_encode($message)); $subject = self::EscapeHead($subject, $options['subjectenc']); $from = self::EscapePart($from, $options['subjectenc']); $to = self::EscapePart($to, $options['subjectenc']); $headers = array("Mime-Version: 1.0", "Content-Type: {$options['contentType']}; charset={$options['encoding']}", "Content-Transfer-Encoding: base64", "X-Mailer: ZTMailer/1.0", "From: {$from}", "Reply-To: {$from}"); if ($bcc) { $bcc = join(', ', $bcc); $headers[] = "Bcc: {$bcc}"; } $headers = join("\r\n", $headers); if (isset($options['messageId'])) { $headers["Message-Id"] = "<{$options['messageId']}>"; } return mail($to, $subject, $message, $headers); }
function sl_send_email($to, $subject, $html, $plain = null, $attachment = null) { if (empty($to)) { return false; } $hash = md5(date('r', time())); $headers['From'] = 'The LoveMachine <*****@*****.**>'; $headers['To'] = $to; if (!empty($html)) { if (empty($plain)) { $h2t = new html2text($html, 75); $plain = $h2t->convert(); } $headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-{$hash}\""; $body = "\n--PHP-alt-{$hash}\nContent-Type: text/plain; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $plain . "\n\n--PHP-alt-{$hash}\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $html . "\n\n--PHP-alt-{$hash}--"; if ($attachment != null && !empty($attachment['name']) && !empty($attachment['content'])) { $headers["Content-Type"] = "multipart/mixed; boundary=\"PHP-mixed-{$hash}\""; //encode it with MIME base64, //and split it into smaller chunks $attachmentContent = chunk_split(base64_encode($attachment['content'])); $body = "\n--PHP-mixed-{$hash}\nContent-Type: multipart/alternative; boundary=\"PHP-alt-{$hash}\"\n\n" . $body . "\n--PHP-mixed-{$hash} \nContent-Type: {$attachment['type']}; name=\"{$attachment['name']}\" \nContent-Transfer-Encoding: base64 \nContent-Disposition: attachment \n\n{$attachmentContent}\n--PHP-mixed-{$hash}-- \n"; } } else { $body = $plain; } send_authmail(array('sender' => 'authuser', 'server' => 'gmail-ssl'), $to, $subject, $body, $headers); return true; }
function _guifi_mac_sum($mac, $sum) { $mac = str_replace(":", "", $mac); $dec = hexdec($mac) + $sum; $smac = str_pad(dechex($dec), 12, '0', STR_PAD_LEFT); return strtoupper(substr(chunk_split($smac, 2, ':'), 0, 17)); }
/** * mail * * mail the message * * @access public * @param string $email_address * @param string $subject * @param string $msg * @param string $headers * @param string $attach_filepath * @return boolean success of send true or false */ public function mail($email_address, $subject, $msg, $headers, $attach_filepath) { $b = 0; $mail_attached = ""; $boundary = md5(uniqid(time(), 1)) . "_xmail"; if (count($attach_filepath) > 0) { for ($a = 0; $a < count($attach_filepath); $a++) { if ($fp = fopen($attach_filepath[$a], "rb")) { $file_name = basename($attach_filepath[$a]); $content[$b] = fread($fp, filesize($attach_filepath[$a])); $mail_attached .= "--" . $boundary . "\r\n" . "Content-Type: image/jpeg; name=\"{$file_name}\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-Disposition: inline; filename=\"{$file_name}\"\r\n\r\n" . chunk_split(base64_encode($content[$b])) . "\r\n"; $b++; fclose($fp); } else { echo $a . "Error!"; } } $mail_attached .= "--" . $boundary . " \r\n"; $add_header = "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"{$boundary}\""; $mail_content = "--" . $boundary . "\r\n" . "Content-Type: text/plain; charset=iso-8859-1; format=flowed\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n" . $msg . "\r\n\r\n" . $mail_attached; return mail($email_address, $subject, $mail_content, $headers . "\r\n" . $add_header); } else { return mail($email_address, $subject, $msg, "From: " . $email_from); } }
function sendAttachMail($from, $to, $subject, $msg, $attach, $from_name) { $fileatt = $_FILES[$attach]['tmp_name']; $fileatt_type = $_FILES[$attach]['type']; $fileatt_name = $_FILES[$attach]['name']; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt, 'rb'); $data = fread($file, filesize($fileatt)); fclose($file); $data = chunk_split(base64_encode($data)); if (trim($from_name) == '') { $from_name = $from; } $headers .= 'From: ' . $from_name . ' <' . $from . '>' . "\r\n"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed; charset=\"iso-8859-1\"\n" . " boundary=\"{" . $this->mime_boundary . "}\""; /*$message = "This is a multi-part message in MIME format.\n\n" . "--{".$this->mime_boundary."}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $msg . "{".$this->mime_boundary."}\n\n";*/ $message = $msg; $message .= "--{" . $this->mime_boundary . "}\n" . "Content-Type: {" . $fileatt_type . "};\n" . " name=\"{" . $fileatt_name . "}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{" . $fileatt_name . "}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{" . $this->mime_boundary . "}--\n"; mail($to, $subject, $message, $headers); } }
function mail_attachments($files, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message, $cc, $bcc) { $uid = md5(uniqid(time())); $header = "From: " . $from_name . " <" . $from_mail . ">\r\n"; $header .= "Reply-To: " . $replyto . "\r\n"; $header .= "cc : < {$cc} > \r\n"; // comma saparated emails $header .= "Bcc : < {$bcc} >\r\n"; // comma saparated emails $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--" . $uid . "\r\n"; $header .= "Content-type:text/html; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message . "\r\n\r\n"; foreach ($files as $filename) { $file = $path . $filename; // path should be document root path. $name = basename($file); $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $header .= "--" . $uid . "\r\n"; $header .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"" . $filename . "\"\r\n\r\n"; $header .= $content . "\r\n\r\n"; } $header .= "--" . $uid . "--"; return @mail($mailto, $subject, $message, $header); }
/** * Send a multipart/alternative message with Text and HTML versions * * @param fromName name of the sender * @param fromEmail email fo the sender * @param replyTo replyTo address to direct responses * @param toEmail destination email address * @param messageSubject subject of the message * @param htmlVersion html version of the message * @param textVersion text only version of the message * @param additionalMailHeader additions to the smtp mail header * @param optional uid user id of the destination user */ public static function send($params) { call_hooks('emailer_send_prepare', $params); $email_textonly = False; if (x($params, "uid")) { $email_textonly = get_pconfig($params['uid'], "system", "email_textonly"); } $fromName = email_header_encode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); // generate a mime boundary $mimeBoundary = rand(0, 9) . "-" . rand(10000000000, 99999999999) . "-" . rand(10000000000, 99999999999) . "=:" . rand(10000, 99999); // generate a multipart/alternative message header $messageHeader = $params['additionalMailHeader'] . "From: {$fromName} <{$params['fromEmail']}>\n" . "Reply-To: {$fromName} <{$params['replyTo']}>\n" . "MIME-Version: 1.0\n" . "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\""; // assemble the final multipart message body with the text and html types included $textBody = chunk_split(base64_encode($params['textVersion'])); $htmlBody = chunk_split(base64_encode($params['htmlVersion'])); $multipartMessageBody = "--" . $mimeBoundary . "\n" . "Content-Type: text/plain; charset=UTF-8\n" . "Content-Transfer-Encoding: base64\n\n" . $textBody . "\n"; if (!$email_textonly && !is_null($params['htmlVersion'])) { $multipartMessageBody .= "--" . $mimeBoundary . "\n" . "Content-Type: text/html; charset=UTF-8\n" . "Content-Transfer-Encoding: base64\n\n" . $htmlBody . "\n"; } $multipartMessageBody .= "--" . $mimeBoundary . "--\n"; // message ending // send the message $hookdata = array('to' => $params['toEmail'], 'subject' => $messageSubject, 'body' => $multipartMessageBody, 'headers' => $messageHeader); //echo "<pre>"; var_dump($hookdata); killme(); call_hooks("emailer_send", $hookdata); $res = mail($hookdata['to'], $hookdata['subject'], $hookdata['body'], $hookdata['headers']); logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG); logger("return value " . ($res ? "true" : "false"), LOGGER_DEBUG); return $res; }
/** * send * 必有方法,发送时调用. * * config参数为getOptions取得的所有项的配置结果 * * @param mixed $target ['email'] * @param mixed $title * @param mixed $config */ public function send($target, $title, $content, $config) { logger::debug(__CLASS__ . var_export(func_get_args(), 1)); $new_msg = array('member_id' => $target['member_id'], 'target' => $target['email'], 'subject' => $title, 'content' => $content, 'createtime' => time(), 'msg_type' => 'email', 'status' => 'sent'); app::get('b2c')->model('member_msg')->save($new_msg); if (!($email_to = $target['email'])) { return false; } if ($config['sendway'] == 'mail') { $this->email = vmc::singleton('desktop_email_email'); } $this->email->Sender = $this->Sender = $config['usermail']; $this->email->Subject = $this->Subject = $this->email->inlineCode($title); $From = $this->email->inlineCode(app::get('site')->getConf('site_name')) . '<' . $config['usermail'] . '>'; $header = array('Return-path' => '<' . $config['usermail'] . '>', 'Date' => date('r'), 'From' => $From, 'MIME-Version' => '1.0', 'Subject' => $this->Subject, 'To' => $email_to, 'Content-Type' => 'text/html; charset=UTF-8; format=flowed', 'Content-Transfer-Encoding' => 'base64'); $body = chunk_split(base64_encode($content)); $header = $this->email->buildHeader($header); $config['sendway'] = $config['sendway'] ? $config['sendway'] : 'smtp'; switch ($config['sendway']) { case 'sendmail': $result = $this->email->SendmailSend($email_to, $header, $body); break; case 'mail': $result = $this->email->MailSend($email_to, $header, $body); break; case 'smtp': $result = $this->email->SmtpSend($email_to, $header, $body, $config); break; default: $result = false; break; } return $result; }
function emailWithAttachment($to, $pdf) { $sendermail = '*****@*****.**'; // email fields: to, from, subject, and so on $from = "{$sendermail}"; $subject = "Fax"; $message = " "; $headers = "From: {$from}"; $filename = 'attachment-order.pdf'; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary $message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // preparing attachments $message .= "--{$mime_boundary}\n"; $data = $pdf->render(); $data = chunk_split(base64_encode($data)); $message .= "Content-Type: application/pdf; name=\"" . $filename . "\"\n" . "Content-Description: " . $filename . "\n" . "Content-Disposition: attachment;\n" . " filename=\"" . $filename . "\"; \n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $message .= "--{$mime_boundary}--"; $returnpath = "-f" . $sendermail; $ok = @mail($to, $subject, $message, $headers, $returnpath); }
function build_message($part) { $message = $part["message"]; $message = chunk_split(base64_encode($message)); $encoding = "base64"; return "Content-Type: " . $part["ctype"] . ($part["name"] ? "; name = \"" . $part["name"] . "\"" : "") . "\nContent-Transfer-Encoding: {$encoding}\n\n{$message}\n"; }
/** * Simple function to send an email on failure of MySQL commands * @param string $subject * @param string $body * @param array $trace * @return boolean */ function sql_mailman($subject, $body, $trace) { ob_start(); dump($trace); $trace = ob_get_contents(); ob_end_clean(); global $MYSQL_OPTS; $to = DEBUG_EMAIL; $from = "noreply@{$MYSQL_OPTS['domain_name']}"; $params = "-f" . $from; $headers = "From: MySQL Debug <" . $from . ">\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"MIME-BOUNDARY\"\r\n"; $message = "\r\n"; $message .= "--MIME-BOUNDARY\r\n"; $message .= "Content-type: text/html; charset=US-ASCII\r\n"; $message .= "\r\n"; $message .= "<HTML>\r\n" . "<HEAD>\r\n" . "<STYLE TYPE='text/css'>\r\n" . "#SQL, #SQL TD, #SQL TH { font-family: Tahoma, Helvetica, sans-serif; font-size: 10pt; color: #000000; }\r\n" . "#SQL { border: 1px solid #000000 }\r\n" . "#SQL TD { border: 1px solid #000000 }\r\n" . "#SQL TH { background: #000000; color: #FFFFFF }\r\n" . "</STYLE>\r\n" . "</HEAD>\r\n" . "<BODY BGCOLOR=WHITE>\r\n" . "{$body}\r\n" . "</BODY>\r\n" . "</HTML>\r\n"; $message .= "\r\n"; $message .= "--MIME-BOUNDARY\r\n"; $message .= "Content-Type: text/html;\n" . " name=\"backtrace.html\"\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n" . chunk_split(base64_encode($trace)) . "\r\n\r\n" . "--MIME-BOUNDARY--"; ob_start(); $ok = mail($to, $subject, $message, $headers, $params); $buffer = ob_get_contents(); ob_clean(); return $ok ? true : false; }
function encode($target_file) { $finalimage = chunk_split(base64_encode($target_file)); $sql = "INSERT INTO files_table SET filedata='{$finalimage}'"; global $conn; mysqli_query($conn, $sql); }
function Field() { $parts = explode("\n", chunk_split($this->value, 4, "\n")); $parts = array_pad($parts, 4, ""); $field = "<span id=\"{$this->name}_Holder\" class=\"creditCardField\">" . "<input autocomplete=\"off\" name=\"{$this->name}[0]\" value=\"{$parts['0']}\" maxlength=\"4\"" . $this->getTabIndexHTML(0) . " /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[1]\" value=\"{$parts['1']}\" maxlength=\"4\"" . $this->getTabIndexHTML(1) . " /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[2]\" value=\"{$parts['2']}\" maxlength=\"4\"" . $this->getTabIndexHTML(2) . " /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"{$parts['3']}\" maxlength=\"4\"" . $this->getTabIndexHTML(3) . " /></span>"; return $field; }
function _dec_to_ip($ip) { $hex_str = chunk_split(sprintf("%08X", $ip), 2, ':'); // return sprintf("%08X",$ip); list($hex1, $hex2, $hex3, $hex4) = split('\\:', $hex_str, 4); return base_convert($hex1, 16, 10) . "." . base_convert($hex2, 16, 10) . "." . base_convert($hex3, 16, 10) . "." . base_convert($hex4, 16, 10); }
/** * @return array */ protected function toView() { /* @global CUser $USER */ global $USER; if (!CModule::includeModule('security')) { return array('MESSAGE' => Loc::getMessage('SECURITY_AUTH_OTP_MANDATORY_MODULE_ERROR')); } if (!Otp::isOtpRequiredByMandatory()) { return array('MESSAGE' => Loc::getMessage('SECURITY_AUTH_OTP_MANDATORY_NOT_REQUIRED')); } if ($USER->IsAuthorized()) { return array('MESSAGE' => Loc::getMessage('SECURITY_AUTH_OTP_MANDATORY_AUTH_ERROR')); } $deferredParams = Otp::getDeferredParams(); if (!$deferredParams['USER_ID']) { return array('MESSAGE' => Loc::getMessage('SECURITY_AUTH_OTP_MANDATORY_UNKNOWN_ERROR')); } $result = array(); $otp = Otp::getByUser($deferredParams['USER_ID']); $otp->regenerate(); $result['SECRET'] = $otp->getHexSecret(); $result['TYPE'] = $otp->getType(); $result['APP_SECRET'] = $otp->getAppSecret(); $result['APP_SECRET_SPACED'] = chunk_split($result['APP_SECRET'], 4, ' '); $result['PROVISION_URI'] = $otp->getProvisioningUri(); $result['SUCCESSFUL_URL'] = $this->arParams['SUCCESSFUL_URL']; $result['TWO_CODE_REQUIRED'] = $otp->getAlgorithm()->isTwoCodeRequired(); $result['OTP'] = $otp; return $result; }
function testBigPCRE() { $dir = new WatchmanDirectoryFixture(); $root = $dir->getPath(); touch("{$root}/foo.c"); touch("{$root}/bar.txt"); $this->watch($root); $fill = str_repeat('lemon\\.php', 3600); $pcre = '^(' . chunk_split($fill, 100, '|') . 'sss)'; $res = $this->watchmanCommand('query', $root, array('expression' => array('pcre', $pcre, 'wholename'), 'fields' => array('name'))); // Some libraries will happily parse this big pcre if (isset($res['error'])) { if ($res['error'] == "failed to parse query: unknown expression term 'pcre'") { $this->assertSkipped('no PCRE support'); } $possible = array('code 50 repeated subpattern is too long', 'code 20 regular expression is too large'); $matched = false; foreach ($possible as $frag) { if (preg_match("/^failed to parse query: invalid i?pcre: " . "{$frag} at offset \\d+/", $res['error'])) { $matched = true; } } $this->assertEqual(true, $matched, "got useful message: " . substr($res['error'], 0, 128)); } }
/** * send * 必有方法,发送时调用 * * config参数为getOptions取得的所有项的配置结果 * * @param mixed $to * @param mixed $message * @param mixed $config * @access public * @return void */ function send($to, $subject, $body, $config) { if ($config['sendway'] == "mail") { $this->email = kernel::single('desktop_email_email'); } $this->Sender = $config['usermail']; $this->Subject = $this->email->inlineCode($subject); $this->email->Sender = $this->Sender; $this->email->Subject = $this->Subject; $header = array('Return-path' => '<' . $config['usermail'] . '>', 'Date' => date('r'), 'From' => $this->email->inlineCode(app::get('site')->getConf('site.name')) . '<' . $config['usermail'] . '>', 'MIME-Version' => '1.0', 'Subject' => $this->Subject, 'To' => $to, 'Content-Type' => 'text/html; charset=UTF-8; format=flowed', 'Content-Transfer-Encoding' => 'base64'); $body = chunk_split(base64_encode($body)); $header = $this->email->buildHeader($header); $config['sendway'] = $config['sendway'] ? $config['sendway'] : 'smtp'; switch ($config['sendway']) { case "sendmail": $result = $this->email->SendmailSend($to, $header, $body); break; case "mail": $result = $this->email->MailSend($to, $header, $body); break; case "smtp": $result = $this->email->SmtpSend($to, $header, $body, $config); break; default: # trigger_error('mailer_not_supported',E_ERROR); $result = false; break; } return $result; }
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: " . $from_name . " <" . $from_mail . ">\r\n"; $header .= "Reply-To: " . $replyto . "\r\n"; $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--" . $uid . "\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message . "\r\n\r\n"; $header .= "--" . $uid . "\r\n"; $header .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"" . $filename . "\"\r\n\r\n"; $header .= $content . "\r\n\r\n"; $header .= "--" . $uid . "--"; if (mail($mailto, $subject, "", $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!"; } }