public function submit() { $this->load->language('common/contact'); if ($this->validate()) { unset($this->session->data['captcha']); $this->language->load('common/contact'); $mail = new \Core\Mail(); $mail->tags = array('Contact Request'); $mail->mandrill_key = $this->config->get('config_mandrill_key'); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_mail_smtp_hostname'); $mail->username = $this->config->get('config_mail_smtp_username'); $mail->password = $this->config->get('config_mail_smtp_password'); $mail->port = $this->config->get('config_mail_smtp_port'); $mail->timeout = $this->config->get('config_mail_smtp_timeout'); $post = $this->request->post; unset($post['custom_field']); $mailbody = "Contact form Submission \n"; $mailbody .= $this->language->get('entry_name') . ": " . $this->request->post['name'] . "\n"; $mailbody .= $this->language->get('entry_email') . ": " . $this->request->post['email'] . "\n"; $mailbody .= $this->language->get('entry_enquiry') . ": " . $this->request->post['enquiry'] . "\n"; $fields = $this->model_account_custom_field->getCustomFields(); foreach ($fields as $cfield) { if ($cfield['location'] == 'contact') { $mailbody .= $cfield['name'] . ": " . $this->request->post['custom_field'][$cfield['custom_field_id']] . "\n"; $post['custom_field'][$cfield['name']] = $this->request->post['custom_field'][$cfield['custom_field_id']]; } } $mailbody .= "\n\n\n------------------------------------------\n"; $mailbody .= "" . DATE("Y-m-d h:i a") . " | " . $this->request->server['REMOTE_ADDR']; $this->event->trigger('contact.form.submit.body', $mailbody); $mailsubject = sprintf($this->language->get('email_subject'), $this->request->post['name']); $this->event->trigger('contact.form.submit.subject', $mailsubject); $this->load->model('account/contact'); $this->model_account_contact->addContact($post); $mail->setTo($this->config->get('config_email')); $mail->setFrom($this->config->get('config_email')); $mail->setSender($this->request->post['name']); $mail->setReplyTo($this->request->post['email']); $mail->setSubject($mailsubject); $mail->setText($mailbody); $mail->setHtml(nl2br($mailbody)); $mail->send(); $data['success'] = $this->language->get('text_success'); // $this->redirect($this->url->link('common/contact/success')); } else { $data['error'] = $this->error; } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($data)); }
public function send() { $this->load->language('marketing/contact'); $json = array(); if ($this->request->server['REQUEST_METHOD'] == 'POST') { if (!$this->user->hasPermission('modify', 'marketing/contact')) { $json['error']['warning'] = $this->language->get('error_permission'); } if (!$this->request->post['subject']) { $json['error']['subject'] = $this->language->get('error_subject'); } if (!$this->request->post['message']) { $json['error']['message'] = $this->language->get('error_message'); } if (!$json) { $store_name = $this->config->get('config_name'); $this->load->model('marketing/subscriber'); $this->load->model('sale/customer'); $this->load->model('sale/customer_group'); if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $email_total = 0; $emails = array(); $override_permission = isset($this->request->post['override_permission']) ? true : false; switch ($this->request->post['to']) { case 'newsletter': $customer_data = array('filter_opt_in' => 1, 'start' => ($page - 1) * 10, 'limit' => 10); $email_total = $this->model_marketing_subscriber->getTotalSubscribers($customer_data); $results = $this->model_marketing_subscriber->getSubscribers($customer_data); foreach ($results as $result) { $emails[] = $result['email']; } break; case 'customer_all': $customer_data = array('start' => ($page - 1) * 10, 'limit' => 10); if (!$override_permission) { $customer_data['filter_newsletter'] = '1'; } $email_total = $this->model_sale_customer->getTotalCustomers($customer_data); $results = $this->model_sale_customer->getCustomers($customer_data); foreach ($results as $result) { $emails[] = $result['email']; } break; case 'customer_group': $customer_data = array('filter_customer_group_id' => $this->request->post['customer_group_id'], 'start' => ($page - 1) * 10, 'limit' => 10); if (!$override_permission) { $customer_data['filter_newsletter'] = '1'; } $email_total = $this->model_sale_customer->getTotalCustomers($customer_data); $results = $this->model_sale_customer->getCustomers($customer_data); foreach ($results as $result) { $emails[$result['customer_id']] = $result['email']; } break; case 'customer': if (!empty($this->request->post['customer'])) { foreach ($this->request->post['customer'] as $customer_id) { $customer_info = $this->model_sale_customer->getCustomer($customer_id); if ($customer_info && ($override_permission || $customer_info['newsletter'])) { $emails[] = $customer_info['email']; } } } break; } $json['emails'] = $emails; if ($emails) { $start = ($page - 1) * 10; $end = $start + 10; if ($end < $email_total) { $json['success'] = sprintf($this->language->get('text_sent'), $start, $email_total); } else { $json['success'] = $this->language->get('text_success'); } if ($end < $email_total) { $json['next'] = str_replace('&', '&', $this->url->link('marketing/contact/send', 'token=' . $this->session->data['token'] . '&page=' . ($page + 1), 'SSL')); } else { $json['next'] = ''; } $message = '<html dir="ltr" lang="en">' . "\n"; $message .= ' <head>' . "\n"; $message .= ' <title>' . $this->request->post['subject'] . '</title>' . "\n"; $message .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n"; $message .= ' </head>' . "\n"; $message .= ' <body>'; if ($this->request->post['preheader']) { $message .= '<span style="display:none;">' . $this->request->post['preheader'] . '</span>'; } $message .= html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8') . '</body>' . "\n"; $message .= '</html>' . "\n"; foreach ($emails as $email) { if (preg_match('/^[^\\@]+@.*.[a-z]{2,15}$/i', $email)) { $mail = new \Core\Mail(); $mail->mandrill_key = $this->config->get('config_mandrill_key'); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_mail_smtp_hostname'); $mail->username = $this->config->get('config_mail_smtp_username'); $mail->password = $this->config->get('config_mail_smtp_password'); $mail->port = $this->config->get('config_mail_smtp_port'); $mail->timeout = $this->config->get('config_mail_smtp_timeout'); $mail->tags = array('old_newsletter'); $mail->setTo($email); $mail->setFrom($this->config->get('config_email')); $mail->setSender($store_name); $mail->setSubject($this->request->post['subject']); $mail->setHtml($message); $mail->send(); } } } } } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); }
public function index() { $this->load->language('common/contact'); $this->document->setTitle($this->language->get('heading_title')); if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { unset($this->session->data['captcha']); $this->language->load('common/contact'); $mail = new \Core\Mail(); $mail->tags = array('Contact Request'); $mail->mandrill_key = $this->config->get('config_mandrill_key'); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_mail_smtp_hostname'); $mail->username = $this->config->get('config_mail_smtp_username'); $mail->password = $this->config->get('config_mail_smtp_password'); $mail->port = $this->config->get('config_mail_smtp_port'); $mail->timeout = $this->config->get('config_mail_smtp_timeout'); $post = $this->request->post; unset($post['custom_field']); $mailbody = "Contact form Submission \n"; $mailbody .= $this->language->get('entry_name') . ": " . $this->request->post['name'] . "\n"; $mailbody .= $this->language->get('entry_email') . ": " . $this->request->post['email'] . "\n"; $mailbody .= $this->language->get('entry_enquiry') . ": " . $this->request->post['enquiry'] . "\n"; $fields = $this->model_account_custom_field->getCustomFields(); foreach ($fields as $cfield) { if ($cfield['location'] == 'contact') { $mailbody .= $cfield['name'] . ": " . $this->request->post['custom_field'][$cfield['custom_field_id']] . "\n"; $post['custom_field'][$cfield['name']] = $this->request->post['custom_field'][$cfield['custom_field_id']]; } } $mailbody .= "\n\n\n------------------------------------------\n"; $mailbody .= "" . DATE("Y-m-d h:i a") . " | " . $this->request->server['REMOTE_ADDR']; $this->event->trigger('contact.form.submit.body', $mailbody); $mailsubject = sprintf($this->language->get('email_subject'), $this->request->post['name']); $this->event->trigger('contact.form.submit.subject', $mailsubject); $this->load->model('account/contact'); $this->model_account_contact->addContact($post); $mail->setTo($this->config->get('config_email')); $mail->setFrom($this->config->get('config_email'), $this->request->post['name']); $mail->setReplyTo($this->request->post['email']); $mail->setSender($this->request->post['name']); $mail->setSubject($mailsubject); $mail->setText($mailbody); $mail->setHtml(nl2br($mailbody)); $mail->send(); $this->redirect($this->url->link('common/contact/success')); } $data['breadcrumbs'] = array(); $data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home')); $data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('common/contact')); $data['heading_title'] = $this->language->get('heading_title'); $data['text_location'] = $this->language->get('text_location'); $data['text_store'] = $this->language->get('text_store'); $data['text_contact'] = $this->language->get('text_contact'); $data['text_address'] = $this->language->get('text_address'); $data['text_telephone'] = $this->language->get('text_telephone'); $data['text_fax'] = $this->language->get('text_fax'); $data['text_comment'] = $this->language->get('text_comment'); $data['entry_name'] = $this->language->get('entry_name'); $data['entry_email'] = $this->language->get('entry_email'); $data['entry_enquiry'] = $this->language->get('entry_enquiry'); $data['entry_captcha'] = $this->language->get('entry_captcha'); $data['button_map'] = $this->language->get('button_map'); if (isset($this->error['name'])) { $data['error_name'] = $this->error['name']; } else { $data['error_name'] = ''; } if (isset($this->error['email'])) { $data['error_email'] = $this->error['email']; } else { $data['error_email'] = ''; } if (isset($this->error['enquiry'])) { $data['error_enquiry'] = $this->error['enquiry']; } else { $data['error_enquiry'] = ''; } if (isset($this->error['captcha'])) { $data['error_captcha'] = $this->error['captcha']; } else { $data['error_captcha'] = ''; } if (isset($this->error['custom_field'])) { $data['error_custom_field'] = $this->error['custom_field']; } else { $data['error_custom_field'] = array(); } $data['button_submit'] = $this->language->get('button_submit'); $data['action'] = $this->url->link('common/contact'); /* $this->load->model('tool/image'); if ($this->config->get('config_image')) { $data['image'] = $this->model_tool_image->resize($this->config->get('config_image'), $this->config->get('config_image_location_width'), $this->config->get('config_image_location_height')); } else { $data['image'] = false; } */ $data['store'] = $this->config->get('config_name'); if (isset($this->request->post['name'])) { $data['name'] = $this->request->post['name']; } else { $data['name'] = $this->customer->getFirstName(); } if (isset($this->request->post['email'])) { $data['email'] = $this->request->post['email']; } else { $data['email'] = $this->customer->getEmail(); } if (isset($this->request->post['enquiry'])) { $data['enquiry'] = $this->request->post['enquiry']; } else { $data['enquiry'] = ''; } if (isset($this->request->post['captcha'])) { $data['captcha'] = $this->request->post['captcha']; } else { $data['captcha'] = ''; } $this->load->model('account/custom_field'); $data['custom_fields'] = $this->model_account_custom_field->getCustomFields(); if (isset($this->request->post['custom_field'])) { $data['contact_custom_field'] = $this->request->post['custom_field']; } else { $data['contact_custom_field'] = array(); } $this->document->addScript('view/plugins/datetimepicker/moment.js'); $this->document->addScript('view/plugins/datetimepicker/bootstrap-datetimepicker.min.js'); $this->document->addStyle('view/plugins/datetimepicker/bootstrap-datetimepicker.min.css'); $this->children = array('common/column_top', 'common/column_bottom', 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $this->template = 'common/contact.phtml'; $this->data = $data; $this->response->setOutput($this->render()); }
protected function send_email($to_email, $email_subject, $newsletter_html, $from_email, $from_name, $options = array()) { $mail = new \Core\Mail(); $mail->tags = array('Newsletter System'); $mail->mandrill_key = $this->config->get('config_mandrill_key'); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_mail_smtp_hostname'); $mail->username = $this->config->get('config_mail_smtp_username'); $mail->password = $this->config->get('config_mail_smtp_password'); $mail->port = $this->config->get('config_mail_smtp_port'); $mail->timeout = $this->config->get('config_mail_smtp_timeout'); if (!empty($options['message_id'])) { $mail->message_id = $options['message_id']; } $mail->setFrom($this->config->get('config_email')); if (!empty($options['bounce_email'])) { $mail->setFrom($options['bounce_email']); } $mail->setTo($to_email); $mail->setReplyTo($from_email, $from_name); $mail->setSender($from_name); $mail->setSubject($email_subject); $mail->setHtml($newsletter_html); try { $mail->send(); return true; } catch (\Core\Exception $e) { return false; } }