Example #1
0
 public function send()
 {
     if (!$this->getFrom()) {
         if ($from = waMail::getDefaultFrom()) {
             $this->setFrom($from);
         }
     }
     $mailer = new waMail(waMail::getTransportByEmail(key($this->getFrom())));
     return $mailer->send($this);
 }
 public function sendEmail($to, &$errors)
 {
     if (!$to) {
         $to = waMail::getDefaultFrom();
     }
     if (!$to) {
         $errors['all'] = _ws('Recipient (administrator) email is not valid');
         return false;
     }
     if (!wa($this->app_id)->getCaptcha()->isValid()) {
         $errors['captcha'] = _ws('Invalid captcha');
     }
     $email = $this->post('email');
     $email_validator = new waEmailValidator();
     $subject = trim($this->post('subject', _ws('Website request')));
     $body = trim($this->post('body'));
     if (!$body) {
         $errors['body'] = _ws('Please define your request');
     }
     if (!$email) {
         $errors['email'] = _ws('Email is required');
     } elseif (!$email_validator->isValid($email)) {
         $errors['email'] = implode(', ', $email_validator->getErrors());
     }
     if (!$errors) {
         $m = new waMailMessage($subject, nl2br($body));
         $m->setTo($to);
         $m->setFrom(array($email => $this->post('name')));
         if (!$m->send()) {
             $errors['all'] = _ws('An error occurred while attempting to send your request. Please try again in a minute.');
         } else {
             return true;
         }
     }
     return false;
 }