Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="PrintForm">
- <input type="text" id="txtEmail" />
- <input type="submit" value="Send" />
- </form> <br>
- <form id="CloudForm">
- <input type="text" id="txtEmail" />
- <input type="submit" value="Send" />
- </form>
- <script>
- $(document).ready(function () {
- $("#PrintForm").submit(function (e) {
- e.preventDefault();
- var email = $("#txtEmail").val();
- $.ajax({
- type: 'POST',
- url: "/xxx/AjaxMethod",
- dataType: 'json',
- data: {
- email: email,
- },
- success: function (status) {
- console.log('Send');
- },
- error: function () {
- console.log('something went wrong - debug it!');
- }
- });
- });
- });
- </script><br>
- [HttpPost]
- public JsonResult AjaxMethod(string email)
- {
- var SubjectOne = "Print";
- var SendToPrint = "Print@Print.com";
- var errorMessage = "";
- //BookingViewModel
- Booking book = new Booking {
- Email = email,
- };
- try
- {
- // Initialize WebMail helper
- WebMail.SmtpServer = "smtp";
- WebMail.SmtpPort = 25;
- WebMail.UserName = "email@email.com";
- WebMail.Password = "";
- WebMail.From = "email@email.com";
- WebMail.EnableSsl = true;
- WebMail.SmtpUseDefaultCredentials = false;
- // Send email
- WebMail.Send(to: SendToPrint,
- subject: SubjectOne,
- body: "email: " + email + "<br>"
- );
- }
- catch (Exception ex)
- {
- errorMessage = ex.Message;
- }
- return Json(book);
- }
Add Comment
Please, Sign In to add comment