将不同形式的电子邮件发送到不同的电子邮件地址。

时间:2022-04-21 11:23:01

I have 2 Forms , One for Print and One for Cloud and in each Form i have an input field ,where user should write their email address in input feild and when User Submit button for example In Print Form, it should send an email with users email address (Just inform in input feild) to Print Email address and when user submit button in Cloud Form it should send an email to Cloud Email address.

For example;. if Form = Print send value of Input field in Print Form to Print Email Addresse

if Form = Cloud send value of Input field in Cloud Form to Cloud Email Address

I can get it just work for One Form for example Print , but i dont know how get this things work for the others Forms like Cloud. Can anyone please point me in right direction! thanks :)

我有两种形式,一个在每个表单打印和一个用于云,我有一个输入字段,用户应该写他们的电子邮件地址在输入行业,当用户提交按钮例如打印形式,它应该与用户发送一封电子邮件的电子邮件地址(在输入行业只是通知)打印电子邮件地址,当用户提交按钮在云表单应该云电子邮件地址发送一封电子邮件。例如,。如果形式=打印发送输入字段的值在打印表格打印邮件Addresse如果形式=云输入字段在云的价值形式发送到云邮箱地址我可以只是一种形式例如打印工作,但我不知道如何得到这个工作等其他形式的云。谁能告诉我正确的方向吗?谢谢:)

PrintForm HTML Markup:

PrintForm HTML标记:

 <form id="PrintForm">
                        <input type="text" id="txtEmail" />

                        <input type="submit"  value="Send" />
                    </form> <br>

CloudForm HTML Markup:

CloudForm HTML标记:

 <form id="CloudForm">
                        <input type="text" id="txtEmail" />

                        <input type="submit"  value="Send" />
                    </form>

AJAX:

AJAX:

<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>

Controller:

控制器:

        [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);

        }

3 个解决方案

#1


0  

You need to update your Controller by adding the parameter named formType,

您需要通过添加名为formType的参数来更新控制器,

[HttpPost]
public JsonResult AjaxMethod(string email, string formType)
{
     if(formType == "print")
     {
        //Perform print related stuff
     }
     else if(formType == "cloud")
     {
         //Perform cloud related stuff
     }
}

And updating your AJAX call with data: { email, formType: "print"} for Print form,

并使用数据更新AJAX调用:{email, formType:打印表单的"print"},

 $.ajax({
            type: 'POST',
            url: "/xxx/AjaxMethod",
            dataType: 'json',
            data:  {
               email: email,
               formType: "print"
            },
            success: function (status) {
                console.log('Send');
            },
            error: function () {
                console.log('something went wrong - debug it!');
            }
        });

data: { email, formType: "cloud"} for Cloud form,

数据:{email, formType: "cloud"}云形式,

$.ajax({
            type: 'POST',
            url: "/xxx/AjaxMethod",
            dataType: 'json',
            data:  {
               email: email,
               formType: "cloud"
            },
            success: function (status) {
                console.log('Send');
            },
            error: function () {
                console.log('something went wrong - debug it!');
            }
        });

#2


1  

Register a submit event on the cloud form just like you do for the print form.

在云表单上注册一个提交事件,就像打印表单一样。

 $("#CloudForm").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!');
            }
        });

    });

If both the CloudForm and PrintForm are on the same page, you will have to change the id of the textbox inputs so that they both have an unique ID.

如果CloudForm和PrintForm都在同一个页面上,您必须更改文本框输入的id,以便它们都具有唯一的id。

#3


1  

Add a class to the two forms:

在这两种形式中增加一个类:

<form id="PrintForm" id = printFormGroup">

<form id="CloudForm" id = printFormGroup">

and then amend your AJAX to respond to the class:

然后修改你的AJAX以回复这个类:

$(".printFormGroup").submit(function (e) {

This will cover all forms with the same class and will return whatever the user enters.

这将覆盖具有相同类的所有表单,并将返回用户输入的任何内容。

#1


0  

You need to update your Controller by adding the parameter named formType,

您需要通过添加名为formType的参数来更新控制器,

[HttpPost]
public JsonResult AjaxMethod(string email, string formType)
{
     if(formType == "print")
     {
        //Perform print related stuff
     }
     else if(formType == "cloud")
     {
         //Perform cloud related stuff
     }
}

And updating your AJAX call with data: { email, formType: "print"} for Print form,

并使用数据更新AJAX调用:{email, formType:打印表单的"print"},

 $.ajax({
            type: 'POST',
            url: "/xxx/AjaxMethod",
            dataType: 'json',
            data:  {
               email: email,
               formType: "print"
            },
            success: function (status) {
                console.log('Send');
            },
            error: function () {
                console.log('something went wrong - debug it!');
            }
        });

data: { email, formType: "cloud"} for Cloud form,

数据:{email, formType: "cloud"}云形式,

$.ajax({
            type: 'POST',
            url: "/xxx/AjaxMethod",
            dataType: 'json',
            data:  {
               email: email,
               formType: "cloud"
            },
            success: function (status) {
                console.log('Send');
            },
            error: function () {
                console.log('something went wrong - debug it!');
            }
        });

#2


1  

Register a submit event on the cloud form just like you do for the print form.

在云表单上注册一个提交事件,就像打印表单一样。

 $("#CloudForm").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!');
            }
        });

    });

If both the CloudForm and PrintForm are on the same page, you will have to change the id of the textbox inputs so that they both have an unique ID.

如果CloudForm和PrintForm都在同一个页面上,您必须更改文本框输入的id,以便它们都具有唯一的id。

#3


1  

Add a class to the two forms:

在这两种形式中增加一个类:

<form id="PrintForm" id = printFormGroup">

<form id="CloudForm" id = printFormGroup">

and then amend your AJAX to respond to the class:

然后修改你的AJAX以回复这个类:

$(".printFormGroup").submit(function (e) {

This will cover all forms with the same class and will return whatever the user enters.

这将覆盖具有相同类的所有表单,并将返回用户输入的任何内容。