teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

追加編集しました

2019/08/27 10:57

投稿

oyu
oyu

スコア48

title CHANGED
File without changes
body CHANGED
@@ -15,6 +15,8 @@
15
15
  ```
16
16
 
17
17
  ```php
18
+ complete.php
19
+
18
20
  <?php
19
21
  session_start();
20
22
  session_unset();

1

追加編集しました。

2019/08/27 10:56

投稿

oyu
oyu

スコア48

title CHANGED
File without changes
body CHANGED
@@ -12,4 +12,216 @@
12
12
 
13
13
  ```
14
14
  Can't open /virtual/ikeno-derma/public_html/_demo/company_inquiry/log/contact.csv!
15
+ ```
16
+
17
+ ```php
18
+ <?php
19
+ session_start();
20
+ session_unset();
21
+ session_destroy();
22
+ ?>
23
+
24
+ <?php
25
+ include("phpmailer.inc.php");
26
+
27
+
28
+ //edit(メールアドレスのみ。例えば携帯メールアドレスが必須のような場合「if($_POST['email']!="" && $_POST['email_mobile']!=""){」と記述する。)
29
+ //only for mailaddress
30
+ if($_POST['email']!=""){
31
+
32
+ $files = glob('uploads/*');
33
+
34
+ //edit(ファイル添付がある場合、その分だけ用意する。この項目が無かったらコメントアウトすること)if the image exists. you must commentout when this column is nothing.
35
+ //$my_path = "uploads/".$_POST['img'];
36
+ //$my_path2 = "uploads/".$_POST['img2'];
37
+
38
+
39
+ //edit(自動返信メール(管理者、複数指定可))reply mail for admin (you can specify multiple)
40
+ $items[] = array('subject' => '【】ホームページよりお問い合わせがありました。',
41
+ 'header_mail' => $_POST['name'].' 様より、以下のお問い合わせがありました。<br><br><br>',
42
+ 'footer_mail' => '',
43
+ 'send_fromname' => $_POST['name'],
44
+ 'send_from' => $_POST['email'],
45
+ 'send_to' => array('support@netoption.co.jp'),
46
+ );
47
+
48
+ //edit(自動返信メール(エンドユーザ) ※「send_fromname」「send_from」にエンドユーザ向けのFROM表記・メアドを入力する。)reply mail for enduser (input to "send_fromname" & "send_from)
49
+ $items[] = array('subject' => '【】お問い合わせありがとうございます。',
50
+ 'header_mail' => $_POST['name'].' 様<br><br>
51
+ お問い合わせありがとうございます。<br>
52
+ このメールは自動送信メールです。<br>
53
+ 翌営業日を過ぎましてもお問い合わせに対する対応がない場合は、<br>
54
+ お手数をおかけしますがまで<br>
55
+ ご連絡くださいますようお願い申し上げます。<br><br><br>',
56
+ 'footer_mail' => '',
57
+ 'send_fromname' => '',
58
+ 'send_from' => '',
59
+ 'send_to' => array($_POST['email']),
60
+ );
61
+
62
+
63
+ foreach($items as $item)
64
+ {
65
+ //////////////header_mail////////////
66
+ $data= $item['header_mail'];
67
+ ////////////////////////////////////
68
+
69
+
70
+ //edit(管理者・エンドユーザ共通、メールの中心部分)reply mail body for admin & enduser
71
+ $data.= "
72
+ 氏名:<br>".$_POST['name']."<br><br>
73
+ フリガナ:<br>".$_POST['kana']."<br><br>
74
+ 郵便番号:<br>〒".$_POST['postcode']."<br><br>
75
+ ご住所:<br>".$_POST['add1'].$_POST['add2']."<br><br>
76
+ 電話番号:<br>".$_POST['tel1']."-".$_POST['tel2']."-".$_POST['tel3']."<br><br>
77
+ FAX番号:<br>".$_POST['fax1']."-".$_POST['fax2']."-".$_POST['fax3']."<br><br>
78
+ メールアドレス:<br>".$_POST['email']."<br><br>
79
+ お問い合わせ内容:<br>".$_POST['message']."<br><br>
80
+ ";
81
+
82
+ //////////////footer_mail////////////
83
+ $data.= $item['footer_mail'];
84
+ ////////////////////////////////////
85
+
86
+ $fromname = $item['send_fromname'];
87
+
88
+ ////////////// Subject ////////////
89
+ $subject = $item['subject'];
90
+ ////////////////////////////////////
91
+ $send_from = $item['send_from'];
92
+
93
+ $body = $data;
94
+
95
+ $mailBody = $body;
96
+ $objMail = new PHPMailer();
97
+
98
+ $objMail->ContentType = "text/html";
99
+ $objMail->CharSet = "utf-8";
100
+ $objMail->Mailer = "mail";
101
+ $objMail->Priority = 3;
102
+ $objMail->From = $send_from;
103
+
104
+ $objMail->FromName =$fromname;
105
+ $objMail->Subject = $subject;
106
+ //edit(ファイル添付がある場合↑と合わせる。)if the image exists. (same ↑.)
107
+ if($_POST['img']!=""){
108
+ $objMail->AddAttachment($my_path);
109
+ }
110
+ if($_POST['img2']!=""){
111
+ $objMail->AddAttachment($my_path2);
112
+ }
113
+
114
+ $objMail->Body = $mailBody;
115
+ //////////////Send to////////////
116
+ foreach($item['send_to'] as $send_to){
117
+ $objMail->AddAddress($send_to);
118
+ }
119
+ ////////////////////////////////////
120
+
121
+ $objMail->Send();
122
+
123
+ }
124
+
125
+ // get all file names
126
+ foreach($files as $file){ // iterate files
127
+ if(is_file($file))
128
+ unlink($file); // delete file
129
+ }
130
+
131
+
132
+ /**
133
+ * Logging class:
134
+ * - contains lfile, lwrite and lclose public methods
135
+ * - lfile sets path and name of log file
136
+ * - lwrite writes message to the log file (and implicitly opens log file)
137
+ * - lclose closes log file
138
+ * - first call of lwrite method will open log file implicitly
139
+ * - message is written with the following format: [d/M/Y:H:i:s] (script name) message */
140
+ //$msg = str_replace("<br>",",",$datalog);
141
+
142
+
143
+ /*--Start Config Log----------------------------------------------------------------*/
144
+
145
+ // Filename of log to use when none is given to write_log , and log folder change permission to 777
146
+
147
+ //edit(ログファイル設定 DEFAULT_LOGはサーバに合わせること)logfile (DEFAULT_LOG is setting for server)
148
+ define("DEFAULT_LOG","/virtual/ikeno-derma/public_html/_demo/company_inquiry/log/contact.csv");
149
+ $datalog.='氏名:'.$_POST['name'].'';
150
+ $datalog.=",";
151
+ $datalog.='フリガナ:'.$_POST['kana'].'';
152
+ $datalog.=",";
153
+ $datalog.='郵便番号:'.$_POST['postcode'].'';
154
+ $datalog.=",";
155
+ $datalog.='ご住所:'.$_POST['add2'].'';
156
+ $datalog.=",";
157
+ $datalog.='電話番号:'.$_POST['tel'].'';
158
+ $datalog.=",";
159
+ $datalog.='FAX番号:'.$_POST['fax'].'';
160
+ $datalog.=",";
161
+ $datalog.='メールアドレス:'.$_POST['email'].'';
162
+ $datalog.=",";
163
+ $datalog.='お問い合わせ内容:'.$_POST['message'].'';
164
+
165
+ /*--END Config Log----------------------------------------------------------------*/
166
+
167
+
168
+
169
+
170
+ $msg = $datalog;
171
+ class Logging {
172
+ // declare log file and file pointer as private properties
173
+ private $log_file, $fp;
174
+ // set log file (path and name)
175
+ public function lfile($path) {
176
+ $this->log_file = $path;
177
+ }
178
+ // write message to the log file
179
+ public function lwrite($message) {
180
+ // if file pointer doesn't exist, then open log file
181
+ if (!is_resource($this->fp)) {
182
+ $this->lopen();
183
+ }
184
+ // define script name
185
+ $script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME);
186
+ // define current time and suppress E_WARNING if using the system TZ settings
187
+ // (don't forget to set the INI setting date.timezone)
188
+ $time = @date('[d/M/Y:H:i:s]');
189
+ // write current time, script name and message to the log file
190
+ // fwrite($this->fp, "$time ($script_name) $message" . PHP_EOL);
191
+ fwrite($this->fp, "$time , $message" . PHP_EOL);
192
+ }
193
+ // close log file (it's always a good idea to close a file when you're done with it)
194
+ public function lclose() {
195
+ fclose($this->fp);
196
+ }
197
+ // open log file (private method)
198
+ private function lopen() {
199
+ $log_file_default = DEFAULT_LOG;
200
+ // define log file from lfile method or use previously set default
201
+ $lfile = $this->log_file ? $this->log_file : $log_file_default;
202
+ // open log file for writing only and place file pointer at the end of the file
203
+ // (if the file does not exist, try to create it)
204
+ $this->fp = fopen($lfile, 'a') or exit("Can't open $lfile!");
205
+ }
206
+ }
207
+
208
+ // Logging class initialization
209
+ $log = new Logging();
210
+
211
+ // set path and name of log file (optional)
212
+ $log->lfile(DEFAULT_LOG);
213
+
214
+ // write message to the log file
215
+ $log->lwrite($msg);
216
+
217
+ // close log file
218
+ $log->lclose();
219
+
220
+ }else{
221
+
222
+ header("Location: index.php");
223
+
224
+ }
225
+
226
+ ?>
15
227
  ```