public function checkAdministratorUserExists($email, $password) { try { if (empty($email)) { throw new Exception('NO_EMAIL'); } } catch (Exception $e) { return $e; } try { if (empty($password)) { throw new Exception('NO_PASSWORD'); } } catch (Exception $e) { return $e; } $validator = new \Zend\Validator\EmailAddress(); if ($validator->isValid($email)) { // email appears to be valid } else { // email is invalid; print the reasons foreach ($validator->getMessages() as $message) { echo "{$message}\n"; } } }
public function index04Action() { echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>"; $validator = new \Zend\Validator\EmailAddress(); $input = "*****@*****.**"; //ok $input = "trongle@gmail"; //not ok $input = "trongle@.com"; //not ok if (!$validator->isValid($input)) { $message = $validator->getMessages(); echo current($message); } else { echo "ok"; } return false; }
protected function emailSubmitPrecheck() { $request = $this->getRequest(); if ($request->isPost()) { $post_data = $request->getPost(); $email = trim($post_data['email']); if (empty($email)) { throw new \Exception('Empty value!'); } $validator = new \Zend\Validator\EmailAddress(); $msg = ''; if (!$validator->isValid($email)) { // email is invalid; print the reasons foreach ($validator->getMessages() as $messageId => $message) { $msg .= "Validation failure '{$messageId}': {$message}\n"; } throw new \Exception($msg); } else { return true; } } else { throw new \Exception('Error method!'); } }
function notify_modify_to_admin($task, $user, $key, $old_value, $new_value) { $reporter = $user['reporter']; $assign = $user['assign']; $agency = $user['agency']; $provider = $user['provider']; $validator = new \Zend\Validator\EmailAddress(); $email = NULL; $getcontent = file_get_contents(MailHelper::EMAIL_TEMPLETE_PATH . 'modify_task_admin.html'); $subject = sprintf(MailHelper::EMAIL_SUBJECT_FILTER_TEMPLATE, $task['id'], $task['certificate'], MailHelper::MESSAGE_MODIFY_SUBJECT); /* add hightlight base on key,old value, new value */ $getcontent = str_replace("{|" . $key . "|}", "<span style=\"text-decoration: line-through;\"> " . $old_value . " </span> <strong> <font color=red>" . $new_value . "</font></strong>", $getcontent); if ($key == Config::cost_sell_id) { $getcontent = str_replace("{|du_no_kh|}", "<strong> <font color=red>{|du_no_kh|}</font></strong>", $getcontent); } else { if ($key == Config::cost_buy_id) { $getcontent = str_replace("{|du_no_cc|}", "<strong> <font color=red>{|du_no_cc|} </font></strong>", $getcontent); } } /* add other values */ $getcontent = str_replace('{|message|}', MailHelper::MESSAGE_MODIFY_CONTENT, $getcontent); $getcontent = str_replace('{|process_id|}', $task['process_name'], $getcontent); $getcontent = str_replace('{|ma_ho_so|}', $task['id'], $getcontent); $getcontent = str_replace('{|link|}', MailHelper::REAL_SERVER_SITE . MailHelper::ADMIN_LINK . $task['id'], $getcontent); $getcontent = str_replace('{|thanh_toan|}', 0, $getcontent); $getcontent = str_replace('{|ten_khach_hang|}', $agency->username, $getcontent); $getcontent = str_replace('{|ten_nha_cung_cap|}', $provider->username, $getcontent); $getcontent = str_replace('{|cost_sell|}', number_format($task['cost_sell']), $getcontent); $getcontent = str_replace('{|cost_buy|}', number_format($task['cost_buy']), $getcontent); $getcontent = str_replace('{|date_open|}', Date::changeDateSQLtoVN($task['date_open']), $getcontent); $getcontent = str_replace('{|date_end|}', Date::changeDateSQLtoVN($task['date_end']), $getcontent); $getcontent = str_replace('{|agency_note|}', $task['agency_note'], $getcontent); $getcontent = str_replace('{|date_open_pr|}', Date::changeDateSQLtoVN($task['date_open_pr']), $getcontent); $getcontent = str_replace('{|date_end_pr|}', Date::changeDateSQLtoVN($task['date_end_pr']), $getcontent); $getcontent = str_replace('{|provider_note|}', $task['provider_note'], $getcontent); $getcontent = str_replace('{|du_no_kh|}', $task['custumer_debt'], $getcontent); $getcontent = str_replace('{|du_no_cc|}', $task['provider_debt'], $getcontent); $getcontent = str_replace('{|thanh_toan_kh|}', $task['pay_custumer'], $getcontent); $getcontent = str_replace('{|thanh_toan_cc|}', $task['pay_provider'], $getcontent); /* viet add */ $getcontent = str_replace('{|custumer|}', $task['custumer'], $getcontent); $getcontent = str_replace('{|certificate|}', $task['certificate'], $getcontent); $getcontent = str_replace('{|reporter_id|}', $reporter->username, $getcontent); $getcontent = str_replace('{|assign_id|}', $assign->username, $getcontent); $getcontent = str_replace('{|agency_id|}', $agency->username, $getcontent); $getcontent = str_replace('{|provider_id|}', $provider->username, $getcontent); if ($validator->isValid($reporter->email)) { $getcontent1 = str_replace('{|name|}', $reporter->username, $getcontent); $this->SendMail(MailHelper::EMAIL_SYSTEM_NAME, $reporter->email, $subject, $getcontent1); } else { // email is invalid; print the reasons foreach ($validator->getMessages() as $message) { return "{$message}"; } } if ($validator->isValid($assign->email)) { $getcontent2 = str_replace('{|name|}', $assign->username, $getcontent); $this->SendMail(MailHelper::EMAIL_SYSTEM_NAME, $assign->email, $subject, $getcontent2); } else { // email is invalid; print the reasons foreach ($validator->getMessages() as $message) { return "{$message}"; } } //echo $getcontent; return NULL; }