public ActionResult HandleFormSubmit(ContactUsModel model)
        {
            if (!ModelState.IsValid)
                return CurrentUmbracoPage();

            MailMessage mailMessage = new MailMessage();
            string fromEmail = CurrentPage.GetProperty("fromEmail").Value.ToString();
            mailMessage.From = new System.Net.Mail.MailAddress(fromEmail);

            int toDepartmentId = model.ToDepartmentId;
            //TODO Replace this with a database query.
            string toEmail = "*****@*****.**";
            if (toDepartmentId == 1)
            {
                toEmail = "*****@*****.**";
            }
            else if (toDepartmentId == 2)
            {
                toEmail = "*****@*****.**";
            }
            else if (toDepartmentId == 3)
            {
                toEmail = "*****@*****.**";
            }
            mailMessage.To.Add(toEmail);

            string subject = model.Subject;
            string body = "-------------------------------------------------------------------------------\r\n";
            body += "    Message sent from " + model.ReplyToEmail + " on " + DateTime.Now.ToShortDateString() + ".\r\n";
            body += "-------------------------------------------------------------------------------\r\n";
            if (model.Message == null || model.Message == "")
            {
                subject += "<eom>";
            }
            else
            {
                body += model.Message;
            }
            mailMessage.Subject = subject;
            mailMessage.Body = body;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Send(mailMessage);

            var successMessage = CurrentPage.GetProperty("successMessage").Value.ToString();
            TempData["contactUsSuccess"] = successMessage;

            return RedirectToCurrentUmbracoPage();
        }
Пример #2
0
        public ActionResult ContactUs(ContactUsModel model)
        {
            string errorMessage = string.Empty;
            ViewBag.Status = "error";
            if (String.IsNullOrEmpty(model.FullName))
            {
                errorMessage += "Bạn chưa nhập họ tên." + "<br/>";
            }
            if (String.IsNullOrEmpty(model.Email))
            {
                errorMessage += "Bạn chưa nhập email." + "<br/>";
            }
            if (!CommonHelper.IsValidEmail(model.Email))
            {
                errorMessage += "Email bạn nhập chưa hợp lệ." + "<br/>";
            }
            if (String.IsNullOrEmpty(model.Message))
            {
                errorMessage += "Bạn chưa nhập nội dung liên hệ." + "<br/>";
            }

            if (!String.IsNullOrEmpty(errorMessage))
            {
                ViewBag.Mesage = errorMessage;
                return View();
            }

            string body = "Họ tên : " + model.FullName + "<br/>";
            body += "Email : " + model.Email + "<br/>";
            body += "Điện thoại : " + model.Phone + "<br/>";
            body += "Nội dung : " + "<br/>";
            body += model.Message;
            // Gửi cho người liên hệ
            string Email = System.Configuration.ConfigurationManager.AppSettings["Email"];
            bool isSend1 = Utils.SendMail(model.Email, "Cảm ơn bạn đã liên hệ với chúng tôi",
                "Cảm ơn bạn đã liên hệ. Chúng tôi đã nhận được liên hệ của bạn và sẽ liên hệ lại với bạn trong thời gian sớm nhất." +
                "<br/>=====Email được trả lời tự động bởi hệ thống======");
            bool isSend2 = Utils.SendMail(Email, "Liên hệ mới từ website CorsacITC", body);
            if (isSend1 && isSend2)
            {
                ViewBag.Status = "success";
                ViewBag.Message = "Cảm ơn bạn đã gửi thông tin liên hệ đến chúng tôi.";
            }
            ViewBag.Message = "Có lỗi trong quá trình xử lý. Vui lòng thử lại.";
            return View();
        }