Beispiel #1
0
 public function __construct($mailConfig)
 {
     SwiftMailer::getInstance();
     //Set mail config
     if (!is_array($mailConfig)) {
         throw new \Exception('mailConfig parameter must be an array');
     }
     // sender params
     if (!isset($mailConfig['fromEmail'])) {
         throw new \Exception('fromEmail parameter don\'t exists');
     }
     if (!Validate::isEmail($mailConfig['fromEmail'])) {
         throw new \Exception('fromEmail parameter must be a valid email');
     }
     $this->_mailConfig['fromEmail'] = $mailConfig['fromEmail'];
     if (!isset($mailConfig['fromName'])) {
         throw new \Exception('fromName parameter don\'t exists');
     }
     if (!is_string($mailConfig['fromName'])) {
         throw new \Exception('fromName parameter must be a string');
     }
     $this->_mailConfig['fromName'] = $mailConfig['fromName'];
     // receiver params
     if (!isset($mailConfig['toEmail'])) {
         throw new \Exception('toEmai parameter don\'t exists');
     }
     if (!Validate::isEmail($mailConfig['toEmail'])) {
         throw new \Exception('toEmail parameter must be a valid email');
     }
     $this->_mailConfig['toEmail'] = $mailConfig['toEmail'];
     if (!isset($mailConfig['toName'])) {
         throw new \Exception('toName parameter don\'t exists');
     }
     if (!is_string($mailConfig['fromName'])) {
         throw new \Exception('fromName parameter must be a string');
     }
     $this->_mailConfig['toName'] = $mailConfig['toName'];
     //Optional subject of mail params
     if (isset($mailConfig['mailSubject'])) {
         if (!is_string($mailConfig['mailSubject'])) {
             throw new \Exception('mailSubject parameter must be a string');
         }
         $this->_mailConfig['mailSubject'] = $mailConfig['mailSubject'];
     }
 }
Beispiel #2
0
 public function contact()
 {
     //get security
     $security = Security::getSecurity(Security::TYPE_FORM);
     $crsf = $security->getProtection('form1', Form::PROTECTION_CSRF);
     $captcha = $security->getProtection('form1', Form::PROTECTION_CAPTCHA);
     //create new and add to ajax data
     $crsf->create();
     $this->addAjaxDatas('token', $crsf->get());
     $error = false;
     //check security
     if (!$crsf->check(Http::getPost('token'))) {
         $error = true;
     }
     if (!$captcha->check(Http::getPost('captcha'))) {
         $this->addError($this->language->getVar('validate_security'), 'captcha');
         $error = true;
     }
     // send mail
     if ($error) {
         $this->notifyError($this->language->getVar('validate_error'));
     } else {
         //send mail
         SwiftMailer::getInstance();
         $mail = \Swift_Message::newInstance();
         $mail->setFrom(array(ADMIN_EMAIL => $this->language->getVar('site_name')));
         $mail->setTo(CONTACT_EMAIL);
         $mail->setSubject($this->language->getVar('site_name') . ' demande de contact');
         $contents = new MailContents($this->tpl->getPath() . 'mails' . DS . 'contact.tpl.php');
         $contents->addVar('message', nl2br(Http::getPost('message')))->addVar('name', Http::getPost('name'))->addVar('email', Http::getPost('email'))->addVar('subject', Http::getPost('subject'));
         $mail->addPart($contents->getMailContents(), 'text/html');
         $transport = defined('SMTP_SERVER') && !is_null(SMTP_SERVER) && SMTP_SERVER != '' ? \Swift_SmtpTransport::newInstance(SMTP_SERVER, 25) : \Swift_MailTransport::newInstance();
         $mailer = \Swift_Mailer::newInstance($transport);
         $mailer->send($mail);
         $this->notifySuccess($this->language->getVar('validate_success'));
     }
     //set in session
     $crsf->set();
 }