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