Exemplo n.º 1
0
        public HttpResponseMessage Submit(Contact PostData)
        {
            // Save our model
            using (var db = new MessageContext())
            {
                db.Messages.Add(new SavedMessage
                {
                    FirstName = PostData.FirstName,
                    LastName  = PostData.LastName,
                    Email     = PostData.Email,
                    Phone     = PostData.Phone,
                    Subject   = PostData.Subject,
                    Body      = PostData.Message
                });
                db.SaveChanges();
            }

            // Send our email
            MailUtilities.LoginMail("*****@*****.**", "J!qHvpQ~j8`;<MuF", "ContactBot");

            StringBuilder MailBuilder = new StringBuilder();

            MailBuilder.Append($"Name: {PostData.FirstName} {PostData.LastName}<br>");
            MailBuilder.Append($"Email: {PostData.Email}<br>");
            MailBuilder.Append($"Telephone number:{PostData.Phone}<br>");
            MailBuilder.Append($"onderwerp: {PostData.Subject}<br>");
            MailBuilder.Append($"<pre>{PostData.Message}</pre>");

            MailUtilities.SendMail("*****@*****.**", $"Message from {PostData.FirstName} {PostData.LastName}", MailBuilder.ToString());

            var response = new HttpResponseMessage(HttpStatusCode.Created);

            Response.Redirect("/Contact/thankyou");
            return(response);
        }