Пошук по сайту
Результати пошуку за тегами 'attach'.
Знайдено 2 результата
-
Всем привет, Может быть кому-то будет полезно, как послать файл вместе с сообщением со страницы Связаться с нами в Opencart. Тестировалось на OcStore 1.5.5.1.2. Сначала добавим кнопку выбора в файле "../catalog/view/theme/*/template/information/contact.tpl" в нужное нам место: <input type="file" name="file"> Затем используем следующий код для файла "../catalog/controller/information/contact.php": $mail = new Mail(); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_smtp_host'); $mail->username = $this->config->get('config_smtp_username'); $mail->password = $this->config->get('config_smtp_password'); $mail->port = $this->config->get('config_smtp_port'); $mail->timeout = $this->config->get('config_smtp_timeout'); $mail->setTo($this->config->get('config_email')); $mail->setFrom($this->request->post['email']); $mail->setSender($this->request->post['name']); if (file_exists($_FILES['file']['tmp_name'])) { $tempdir = (DIR_DOWNLOAD)."/temp/"; $fileName = $_FILES['file']['name']; $imageTemp = $tempdir.$fileName; move_uploaded_file($_FILES['file']['tmp_name'], $tempdir.$fileName); $mail->addAttachment($tempdir.$fileName); } $mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8')); $mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8'))); $mail->send(); unlink($tempdir.$fileName); $this->redirect($this->url->link('information/contact/success')); При этом обязательно нужно создать папку "temp": "../download/temp/" куда будет забрасываться файл и удаляться после отправки письма. Код простой и не очень безопасный, так как не ограничивает тип файла и размер. Для себе еще модернизировал его, чтобы можно было отправить письмо без текста (указаны только имя, почта и прикреплен файл), для этого надо заменить: $mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8'))); на следующий код: if (utf8_strlen($this->request->post['enquiry']) > 0) {$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));} else {$mail->setText(strip_tags(html_entity_decode($enquiry = ' ', ENT_QUOTES, 'UTF-8')));} Но не забудьте тогда поменять сообщение об ошибке на "Файл должен содержать не более 3000 символов" вместо "Файл должен быть от 3 до 3000 символов".
-
файл удален