public function actionAdd() { if (!isset($_POST['NewsHeader']) || !isset($_POST['NewsPreview']) || !isset($_POST['NewsText']) || !isset($_POST['NewsTags'])) { header("HTTP/1.0 404 Not Found"); throw new E404Exception('Required params can not be null'); } $NewsRecord = new News(); $NewsRecord->NewsHeader = $_POST['NewsHeader']; $NewsRecord->NewsPreview = $_POST['NewsPreview']; $NewsRecord->NewsText = $_POST['NewsText']; $NewsRecord->NewsTags = $_POST['NewsTags']; $NewsRecord->publishdate = 'NOW()'; $NewsRecord->insert(); $mail = new \PHPMailer(); $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->Username = '******'; $mail->Password = '******'; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Port = '465'; $mail->addAddress('*****@*****.**'); $mail->Body = 'Created news'; $mail->AltBody = 'Body created'; $mail->send(); $mail->clearAddresses(); header('Location: ./index.php'); }
public function actionInsert() { $view = new View(); $view->display('insert.php'); $article = new News(); $article->title = $_POST['title']; $article->text = $_POST['text']; $article->insert(); }
public function actionAddNews() { $article = new ModelNews(); $title = $_POST['title']; $text = $_POST['text']; $article->title = $title; $article->text = $text; $article->insert(); $send = new SendMail(); if ($send->send()) { header("Location: http://" . $_SERVER['SERVER_NAME'] . "/"); } else { throw new \Exception("Ошибка при отправлении письма о добавлении новости!"); } }