質問編集履歴
3
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
// メール送信
|
46
46
|
|
47
|
-
$result = $this->
|
47
|
+
$result = $this->Sys->sendMailTemplate('reserved_mail', ['input' => $input]);
|
48
48
|
|
49
49
|
if ($result) {
|
50
50
|
|
2
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -82,6 +82,8 @@
|
|
82
82
|
|
83
83
|
return $this->sendMail($to, $from, $this->getMailSubject($tpl, $data), $this->getMailBody($tpl, $data));
|
84
84
|
|
85
|
+
}
|
86
|
+
|
85
87
|
|
86
88
|
|
87
89
|
function getMailTo($tpl, $data)
|
1
コード詳細を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,3 +11,147 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
よろしくお願いします。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
追記:
|
18
|
+
|
19
|
+
メール送信
|
20
|
+
|
21
|
+
```php
|
22
|
+
|
23
|
+
// 送信するメール取得
|
24
|
+
|
25
|
+
$mails = $this->MailList->getSendMails();
|
26
|
+
|
27
|
+
foreach ($mails as $mail) {
|
28
|
+
|
29
|
+
// 送信先保存
|
30
|
+
|
31
|
+
if (!$this->saveTargetData($mail)) {
|
32
|
+
|
33
|
+
continue;
|
34
|
+
|
35
|
+
};
|
36
|
+
|
37
|
+
$limit = 300;
|
38
|
+
|
39
|
+
$offset = 0;
|
40
|
+
|
41
|
+
while ($targets = $this->MailDeliveryTarget->getTargets($mail, $limit, $offset)) {
|
42
|
+
|
43
|
+
foreach ($targets as $target) {
|
44
|
+
|
45
|
+
// メール送信
|
46
|
+
|
47
|
+
$result = $this->Acz->sendMailTemplate('reserved_mail', ['input' => $input]);
|
48
|
+
|
49
|
+
if ($result) {
|
50
|
+
|
51
|
+
// 送信成功時処理
|
52
|
+
|
53
|
+
} else {
|
54
|
+
|
55
|
+
// 送信失敗時処理
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
unset($targets);
|
62
|
+
|
63
|
+
$offset += $limit;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
sendMailTemplateメソッド
|
72
|
+
|
73
|
+
```php
|
74
|
+
|
75
|
+
function sendMailTemplate($tpl, $data = array())
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
$to = $this->getMailTo($tpl, $data);
|
80
|
+
|
81
|
+
$from = $this->getMailFrom($tpl, $data);
|
82
|
+
|
83
|
+
return $this->sendMail($to, $from, $this->getMailSubject($tpl, $data), $this->getMailBody($tpl, $data));
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
function getMailTo($tpl, $data)
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
return trim(convert_nl($this->_getMailTemplate($tpl."/to", $data), ""));
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
// getMailFrom, getMailSubject, getMailBodyも_getMailTemplateに渡す引数以外は同じ処理
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
function _getMailTemplate($tpl, $data)
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
if (!is_file(dirname(dirname(dirname(__FILE__))).DS."Template".DS."mail".DS.str_replace("/", DS, $tpl).".txt")) {
|
104
|
+
|
105
|
+
return "";
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
$bk = array();
|
112
|
+
|
113
|
+
foreach (array("layout", "ext") as $v) {
|
114
|
+
|
115
|
+
$bk[$v] = $this->Controller->$v;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
$bk_output = $this->Controller->response->body();
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
$this->Controller->layout = "";
|
124
|
+
|
125
|
+
$this->Controller->ext = ".txt";
|
126
|
+
|
127
|
+
$this->Controller->response->body("");
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
$this->Controller->set($data);
|
132
|
+
|
133
|
+
$this->Controller->mail_render = true;
|
134
|
+
|
135
|
+
$this->Controller->render("/".ltrim($tpl, "/")); // この部分での処理速度が伸びていく
|
136
|
+
|
137
|
+
$out = $this->Controller->response->body();
|
138
|
+
|
139
|
+
$this->Controller->mail_render = false;
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
$this->Controller->response->body($bk_output);
|
144
|
+
|
145
|
+
foreach (array("layout", "ext") as $v) {
|
146
|
+
|
147
|
+
$this->Controller->$v = $bk[$v];
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
return $out;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
```
|