Source for file Ethna_MailSender.php
Documentation is available at Ethna_MailSender.php
// vim: foldmethod=marker
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
/** メールテンプレートタイプ: 直接送信 */
define('MAILSENDER_TYPE_DIRECT', 0);
* @author Masaki Fujimoto <fujimoto@php.net>
/** @var array メールテンプレート定義 */
/** @var string メールテンプレートディレクトリ */
/** @var string 送信オプション */
/** @var object Ethna_Backend backendオブジェクト */
/** @var object Ethna_Config 設定オブジェクト */
* Ethna_MailSenderクラスのコンストラクタ
* @param object Ethna_Backend &$backend backendオブジェクト
$this->backend =
& $backend;
$this->config =
& $this->backend->getConfig();
* @param string $option メール送信オプション
* array('filename' => '/tmp/hoge.xls', 'content-type' => 'application/vnd.ms-excel')
* array('name' => 'foo.txt', 'content' => 'this is foo.')
* 'content-type' 省略時は 'application/octet-stream' となる。
* 複数添付するときは上の配列を添字0から始まるふつうの配列に入れる。
* @param string $to メール送信先アドレス (nullのときは送信せずに内容を return する)
* @param string $template メールテンプレート名 or タイプ
* @param array $macro テンプレートマクロ or $templateがMAILSENDER_TYPE_DIRECTのときはメール送信内容)
* @param array $attach 添付ファイル
function send($to, $template, $macro, $attach =
null)
$env_datetime =
_et('%Y/%m/%d %H:%M:%S');
$renderer->setProp("env_datetime", strftime($env_datetime));
$renderer->setProp("env_useragent", $_SERVER["HTTP_USER_AGENT"]);
$renderer->setProp("env_remoteaddr", $_SERVER["REMOTE_ADDR"]);
foreach ($macro as $key =>
$value) {
$renderer->setProp($key, $value);
if (isset
($this->def[$template])) {
$template =
$this->def[$template];
$mail =
$renderer->perform(sprintf('%s/%s', $this->mail_dir, $template), true);
list
($header, $body) =
$this->_parse($mail);
$attach = isset
($attach[0]) ?
$attach :
array($attach);
$body =
"This is a multi-part message in MIME format.\n\n" .
"Content-Type: text/plain; charset=iso-2022-jp\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
foreach ($attach as $part) {
if (isset
($part['content']) ===
false
&& isset
($part['filename']) &&
is_readable($part['filename'])) {
$part['filename'] =
basename($part['filename']);
if (isset
($part['content']) ===
false) {
if (isset
($part['content-type']) ===
false) {
$part['content-type'] =
'application/octet-stream';
if (isset
($part['name']) ===
false) {
$part['name'] =
$part['filename'];
if (isset
($part['filename']) ===
false) {
$part['filename'] =
$part['name'];
"Ethna_Util::encode_MIME('$1')", $part['name']); // XXX: rfc2231
"Ethna_Util::encode_MIME('$1')", $part['filename']);
"Content-Type: " .
$part['content-type'] .
";\n" .
"\tname=\"" .
$part['name'] .
"\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment;\n" .
"\tfilename=\"" .
$part['filename'] .
"\"\n\n";
$body .=
"--$boundary--";
if (isset
($header['mime-version']) ===
false) {
$header['mime-version'] =
array('Mime-Version', '1.0');
if (isset
($header['subject']) ===
false) {
$header['subject'] =
array('Subject', 'no subject in original');
if (isset
($header['content-type']) ===
false) {
$header['content-type'] =
array(
$attach ===
null ?
'text/plain; charset=iso-2022-jp'
:
"multipart/mixed; \n\tboundary=\"$boundary\"",
foreach ($header as $key =>
$value) {
// should be added by mail()
if ($header_line !=
"") {
$header_line .=
$value[0] .
": " .
$value[1];
$wa_config =
'mail_func_workaround';
if ($this->config->get($wa_config) ==
false
&& isset
($this->options[$wa_config]) ==
false) {
$header_line =
str_replace("\n", "\r\n", $header_line);
mail($rcpt, $header['subject'][1], $body, $header_line, $this->option);
mail($rcpt, $header['subject'][1], $body, $header_line);
* @param array $macro ユーザ定義マクロ
* @return array アプリケーション固有処理済みマクロ
* @param string $mail メールテンプレート
list
($header_line, $body) =
preg_split('/\r?\n\r?\n/', $mail, 2);
$header_lines =
explode("\n", $header_line);
foreach ($header_lines as $h) {
if (strstr($h, ':') ==
false) {
list
($key, $value) =
preg_split('/\s*:\s*/', $h, 2);
$header[$i][] =
preg_replace('/([^\x00-\x7f]+)/e', "Ethna_Util::encode_MIME('$1')", $value);
return array($header, $body);
* メールフォーマット用レンダラオブジェクト取得する
* @return object Ethna_Renderer レンダラオブジェクト
* メールフォーマット用レンダラオブジェクト取得する
* @return object Ethna_Renderer レンダラオブジェクト
$renderer =
& $c->getRenderer();
Documentation generated on Fri, 11 Nov 2011 03:59:55 +0900 by phpDocumentor 1.4.3