/** * cakeコマンドに実行権限あるか * * @return bool */ public static function isExecutableCake() { if (MailSend::isWindows()) { // Windowsの場合 // is_executable()はwindowsの場合、exeのみしか判定できないため、一律trueを返す return true; } else { // Linuxの場合 return is_executable(APP . 'Console' . DS . 'cake'); } }
/** * メール送信呼び出し * * @return void */ public static function send() { // バックグラウンドでメール送信 // コマンド例) ./app/Console/cake Mails.mailSend if (MailSend::isWindows()) { // Windowsの場合 exec(APP . 'Console' . DS . 'cake Mails.mailSend send > /dev/null &'); } else { // Linuxの場合 // logrotate問題対応 http://dqn.sakusakutto.jp/2012/08/php_exec_nohup_background.html exec('nohup ' . APP . 'Console' . DS . 'cake Mails.mailSend send > /dev/null &'); } }
/** * afterSave is called after a model is saved. * * @param Model $model モデル * @param bool $created True if this save created a new record * @param array $options Options passed from Model::save(). * @return bool * @see Model::save() * @link http://book.cakephp.org/2.0/ja/models/behaviors.html#ModelBehavior::afterSave */ public function afterSave(Model $model, $created, $options = array()) { $contentKey = $this->__getContentKey($model); $workflowType = Hash::get($this->settings, $model->alias . '.' . self::MAIL_QUEUE_SETTING_WORKFLOW_TYPE); $workflowTypeCheck = array(self::MAIL_QUEUE_WORKFLOW_TYPE_COMMENT, self::MAIL_QUEUE_WORKFLOW_TYPE_ANSWER); if (!in_array($workflowType, $workflowTypeCheck, true)) { // 未来日系の送信日時更新を考慮して delete->insert // コンテンツコメントは、同じ動画に複数コメントしてもコンテンツキー同じで消されると困る&未来日系ありえないため、除外 // 回答も未来日系ありえないため、除外 $model->Behaviors->load('Mails.MailQueueDelete', $this->settings[$model->alias]); /** @see MailQueueDeleteBehavior::deleteQueue() */ $model->deleteQueue($contentKey); // MailQueueDeleteBehaviorはunloadしない。モデル側のactAsで既に、MailQueueDeleteBehavior を読み込んでいる場合、下記エラーが出るため。 // Notice (8): Undefined index: MailQueueDelete [CORE/Cake/Utility/ObjectCollection.php, line 128] // Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object [CORE/Cake/Utility/ObjectCollection.php, line 128] $model->Behaviors->disable('Mails.MailQueueDelete'); } $model->Behaviors->load('Mails.IsMailSend', $this->settings[$model->alias]); $typeKey = $this->settings[$model->alias]['typeKey']; // --- リマインダー /** @see IsMailSendBehavior::isMailSendReminder() */ if ($model->isMailSendReminder()) { $sendTimeReminders = $this->settings[$model->alias]['reminder']['sendTimes']; $this->saveQueue($model, $sendTimeReminders, $typeKey); } $sendTimePublish = $this->__getSendTimePublish($model); $settingPluginKey = $this->__getSettingPluginKey($model); // --- 通常メール /** @see IsMailSendBehavior::isMailSend() */ if ($model->isMailSend(MailSettingFixedPhrase::DEFAULT_TYPE, $contentKey, $settingPluginKey)) { $this->saveQueue($model, array($sendTimePublish), $typeKey); // キューからメール送信 MailSend::send(); } $model->Behaviors->unload('Mails.IsMailSend'); return true; }
public function addText($text) { $this->text = $text; } // Отправка public function send() { if (!$this->validate()) { return false; } return mail($this->email, $this->subject, $this->text); } // Валидация входящих данных private function validate() { // Валидация адреса return filter_var($this->email, FILTER_VALIDATE_EMAIL); } } $mail = new MailSend(); $mail->addEmail('*****@*****.**'); // Добавляем адресс $mail->addSubject('Title message'); // Добавляем тему $mail->addText('Text message'); // Добавляем текст if ($mail->send()) { echo 'Отправлено успешно!'; } else { echo 'Не удалось отправить!'; }
/** * メール設定がされているかどうか * * @return bool */ public function isUserMailSend() { $from = SiteSettingUtil::read('Mail.from'); // Fromが空ならメール未設定のため、メール送らない if (empty($from)) { return false; } // cakeコマンドに実行権限なければ、メール送らない if (!MailSend::isExecutableCake()) { return false; } return true; }
public static function getDomain() { return self::$domain; } public static function getMailAddress() { return self::$mail; } public static function sendMail($name, $address, $message) { $mail_to = self::getMailAddress(); $mail_subject = "Сообщение от пользователя " . $name; $mail_body = $message; $domain = self::getDomain(); $mail_headers = "From: " . $name . "<" . $address . ">\r\nX-Mailer: " . $domain . " Mailer\r\nContent-Type: text/html; charset=utf-8"; return mail($mail_to, $mail_subject, $mail_body, $mail_headers); } public static function send() { $name = htmlspecialchars($_POST["name"], ENT_COMPAT, "UTF-8"); $address = htmlspecialchars($_POST["address"], ENT_COMPAT, "UTF-8"); $message = htmlspecialchars($_POST["message"], ENT_COMPAT, "UTF-8"); $real = htmlspecialchars($_POST["real"], ENT_COMPAT, "UTF-8"); if ($real == 1 && $name != '' && $address != '' && $message != '') { self::sendMail($name, $address, $message); header('location:/index.php'); } } } MailSend::send();
public function registrationEventUsers() { if ($_SERVER['REQUEST_METHOD'] != 'POST' || !array_key_exists('submit_reg', $_POST)) { return false; } $events_id = intval(@$_POST['post_id']); //-- две проверки, но в первой не затрагивается БД, если параметр меньше 1 или имеент другое значение в отличии цифрового! if ($events_id < 1) { $this->errors[] = "Какой то не корректный у вас запрос! " . $events_id; return false; } $sql = "SELECT 1 FROM events_name WHERE event_id = ? LIMIT 1"; $result = count($this->queryExec($sql, array($events_id))); if ($result < 1) { $this->errors[] = "В базе не найдено указанное мероприятие!"; return false; } //$this->fix_print($_POST); foreach ($_POST as $key => $value) { $userData[$key] = $this->filteringData($value, false, 1, 33); if ($key == 'username' || $key == 'useremail' || $key == 'uniqueCode' || $key == 'organization') { if ($key == 'uniqueCode' && USE_EST_STANDARD_ID) { $userData[$key] = intval($userData[$key]); if ($userData[$key] < 1) { $this->errors[] = "Ваш личный код не неправильный !"; return false; } } if (!$value) { return false; } } } $sql = "SELECT 1 FROM `users_for_events` WHERE `user_event_id`= ? AND `user_event_email`= ? LIMIT 1"; $result = $this->queryExec($sql, array($events_id, $userData['useremail']))->fetch(); //var_dump($result); if ($result) { $this->errors[] = "Возможно, такой пользователь уже зарегестрировался!"; return false; } $sql = "INSERT INTO `users_for_events` (`user_event_name`,`user_event_email`,`user_event_id`,`user_isikukood`,`user_organization`,`user_event_group`,`user_event_class`) VALUES (?,?,?,?,?,?,?)"; if (empty($userData['group'])) { $userData['group'] = ""; } if (empty($userData['class'])) { $userData['class'] = ""; } $result = $this->queryExec($sql, array($userData['username'], $userData['useremail'], $events_id, $userData['uniqueCode'], $userData['organization'], $userData['group'], $userData['class'])); // Отправляем пользователю сообщение if (!$result) { $this->errors['not_registered'] = "Ошибка! Вы не зарегестрированны"; return false; } //$this->fix_print($_POST); // Отсылаем письмо пользователю, уведомление, того, что он зарегестрировался на вебсайте $mail = new MailSend(); $mail->getTo($userData['useremail']); if (@$_SESSION['locale'] == 'et') { $title = 'вы зарегестрировались на мероприятие: ' . $userData['post_title']; $body = 'Вы зарегестрировались на сайте мероприятий ' . HOST . '. На мероприятии: <a href="' . HOST . '?posts=' . $events_id . '">' . $userData['post_title'] . '</a>'; $msg_content = file_get_contents(ROOT_PATH . DIRECTORY_SEPARATOR . "templates/mail_templates/email.rus.html"); } else { $title = 'вы зарегестрировались на мероприятие: ' . $userData['post_title']; $body = 'Вы зарегестрировались на сайте мероприятий ' . HOST . '. На мероприятии: <a href="' . HOST . '?posts=' . $events_id . '">' . $userData['post_title'] . '</a>'; $msg_content = file_get_contents(ROOT_PATH . DIRECTORY_SEPARATOR . "templates/mail_templates/email.est.html"); } $mail->getFrom(MAILSENTFROM); $mail->getSubject($title); $msg_content = str_replace('_MSG_TITLE_', $title, $msg_content); $msg_content = str_replace('_MSG_BODY_', $body, $msg_content); $msg_content = str_replace('_MSG_WEBSITE_', HOST, $msg_content); $mail->getMessage($msg_content); // Отправляем письмо пользователю if ($mail->sendingMail()) { $this->errors[] = "Напоминание о регистрации вам отправленно уведомление на почту!"; } $this->errors['registered'] = "Спасибо за регистрацию!"; header("refresh:2; url=" . PATH); return true; }
message('缺少必要参数', $options['url']); } $article = $DB->fetch_one_array("SELECT dateline,alias,closecomment FROM {$db_prefix}articles WHERE articleid='{$articleid}'"); $article['url'] = redirect_permalink($articleid, $article['alias']); if ($comment_parent != 0) { $comment = $DB->fetch_one_array("SELECT commentid, comment_parent, articleid, author, email FROM {$db_prefix}comments WHERE commentid='{$comment_parent}'"); if (!$comment) { message('要回复的评论不存在', $options['url']); } $content = '@' . addslashes($comment['author']) . ': ' . $content; if ($options['url']) { //发送邮件通知 include_once SABLOG_ROOT . 'include/class/mail.class.php'; $fromname = $fromname ? $fromname : substr($sax_email, 0, strpos($sax_email, "@")); $fromdomain = strstr($sax_email, '@'); $m = new MailSend(); $m->setToaddr($comment['email']); $m->setSubject('有人在' . $options['name'] . '回复了您的评论'); $m->setContent('有人在' . $options['name'] . '回复了您的评论, 查看内容链接: ' . $article['url']); $m->setFromaddr($fromname . ' <' . $sax_email . '>'); $m->setDomain($fromdomain); $m->send(); } } if ($article['closecomment']) { message('本文不允许发表评论', $article['url']); } if ($options['seccode'] && $sax_group != 1 && $sax_group != 2) { $clientcode = $_POST['clientcode']; include_once SABLOG_ROOT . 'include/class/seccode.class.php'; $code = new seccode();
/** * メールを送るかどうか - 共通処理 * * @param Model $model モデル * @param string $typeKey メールの種類 * @param string $settingPluginKey 設定を取得するプラグインキー * @return bool */ public function isMailSendCommon(Model $model, $typeKey = MailSettingFixedPhrase::DEFAULT_TYPE, $settingPluginKey = null) { if ($settingPluginKey === null) { $settingPluginKey = Current::read('Plugin.key'); } $from = SiteSettingUtil::read('Mail.from'); // Fromが空ならメール未設定のため、メール送らない if (empty($from)) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } // cakeコマンドに実行権限なければ、メール送らない if (!MailSend::isExecutableCake()) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } /** @see MailSetting::getMailSettingPlugin() */ $mailSettingPlugin = $model->MailSetting->getMailSettingPlugin(null, $typeKey, $settingPluginKey); $isMailSend = Hash::get($mailSettingPlugin, 'MailSetting.is_mail_send'); $isMailSendApproval = Hash::get($mailSettingPlugin, 'MailSetting.is_mail_send_approval'); // プラグイン設定でメール通知 and 承認メール通知をどちらも使わないなら、メール送らない if (!$isMailSend && !$isMailSendApproval) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } $status = Hash::get($model->data, $model->alias . '.status'); // 一時保存はメール送らない if ($status == WorkflowComponent::STATUS_IN_DRAFT) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } $block = Current::read('Block'); // ブロック非公開、期間外はメール送らない if (!$model->MailQueue->isSendBlockType($block, '')) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } return true; }