} else { $mail = new Message(); $mail->setFrom("C-SCAN'16 <{$mailer_username}>")->addTo($_POST['email'])->setSubject("C-SCAN'16 Registration"); $mailer = new Nette\Mail\SmtpMailer(array('host' => 'smtp.gmail.com', 'username' => $mailer_username, 'password' => $mailer_password, 'secure' => 'ssl')); $factory = new ValidatorFactory(new Translator('en')); $messages = array('required' => 'The :attribute field is required.', 'max' => 'Please enter a valid :attribute number.', 'min' => 'Please enter a valid :attribute field.', 'email' => 'Please enter a valid email address.', 'numberic' => 'The :attribute field should consist only of digits.', 'integer' => 'The :attribute field should be selected.', 'digits_between' => 'The :attribute field should be contain minimum of 10 digits.'); if ($_POST['type'] == "student") { $rules = array('college' => 'required|integer', 'faculty' => 'required', 'name' => 'required', 'email' => 'required|email', 'phone' => 'required|numeric|digits_between:10,15', 'course' => 'required', 'semester' => 'required', 'gender' => 'required', 'food' => 'required'); $validator = $factory->make($_POST, $rules, $messages); if ($validator->passes()) { $num = Student::where('college', $_POST['college'])->count(); $_POST['regid'] = $num + 1; if ($v = Student::create($_POST)) { $regid = $v->colg->abbr . "S" . str_pad($_POST['regid'], 3, '0', STR_PAD_LEFT); $name = $_POST['name']; $mail->setHTMLBody("Hi {$name},<br/>You have successfully registered for C-SCAN 2016. Your registration ID is " . $regid . ". The confirmation regarding the same will be done via email on or before 1st February.<br/>For more details and updates, please visit our <a href='http://www.cscan.org.in'>website</a>.<br/><br/>Thank you.<br/><br/>Yours Sincerely,<br/>Organising Team,<br/>C-SCAN 2016."); $mailer->send($mail); } else { $error = ERROR_DB; } } else { $error = ERROR_INVALID; } } else { if ($_POST['type'] == "faculty") { $rules = array('college' => 'required|integer', 'name' => 'required', 'email' => 'required|email', 'phone' => 'required|numeric|digits_between:10,15', 'designation' => 'required', 'interest' => 'required', 'gender' => 'required', 'food' => 'required'); $validator = $factory->make($_POST, $rules, $messages); if ($validator->passes()) { $num = Faculty::where('college', $_POST['college'])->count(); $_POST['regid'] = $num + 1; if ($v = Faculty::create($_POST)) {
/** * Here's the magic * * @param array $recipients * @param null $subject * @param array $data * @throws EmailException */ private function sendEmail($recipients = array(), $subject = '', $data) { // recipients check if (!is_array($recipients)) { $recipients = array($recipients); } if (count($recipients) < 1) { throw new EmailException('No subscribers provided. (possibly none in your system)'); } // try sending e-mail try { $mail = new \Nette\Mail\Message(); $mail->setFrom($this->senderEmail, $this->senderName)->setSubject($subject); foreach ($recipients as $recipient) { $mail->addBcc($recipient); } // set HTML / or plaintext body if ($this->htmlEmail == TRUE) { $mail->setHTMLBody($this->getEmailTemplate($data)); } else { $mail->setBody($this->getEmailTemplate($data)); } $this->mailer->send($mail); } catch (\Exception $e) { throw new EmailException($e->getMessage()); } }