开发者

Modifying an .aspx mailer which draws email address to mail to from a drop down list on a web form:

I need to change the response to a mailer which is gets its instruction form a drop down selection box on the webpage.

The original code is working and appears fairly simple, but it emails the wrong department heads, because it isn't specific enough.

I'm not a coder, but I thought to have a stab at this.

This is the original code:

       public partial class ContactUs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        Calendar cal = new Calendar();
        string dat = cal.TodaysDate.Date.ToLongDateString();

            System.Web.Mail.MailMessage mm = new MailMessage();
            mm.From = "WBS Website<info@wbs.ae>";
            if (DrpDwnType.SelectedItem.Value == "G")
                mm.To = "david@wbs.ae";
            else
                mm.To = "robert@wbs.ae";

            mm.Cc = "wolfi@wbs.ae";
            mm.Bcc = "precise.customer@gmail.com";
            mm.Subject = "Online comments from WBS website visitor, " + TXTFname.Text;
            mm.Body = "<div style='border:solid 2px RED; padding:25px 25px 25px 25px'><br><br> <strong>Online comments from WBS website</strong><br> <br> ------------------------------------- <br> Date : " + dat + "<br> <br> First Name : " + TXTFname.Text + "<br>Last Name : " + TXTLastName.Text + "<br> Email Address : " + TXTEmail.Text + "<br> Contact No : " + TXTMob.Text + "<br> Enquiry Type : " + DrpDwnType.SelectedItem.Text + "<br> <br> <br> The visitor comment : <br> --------------------------------------- <br> " + TXTComment.Text + "</strong><br><br>Further Information : " + RadioButtonList1.SelectedItem.Value.ToString() + "<br><br><br></div>";
            mm.BodyFormat = MailFormat.Html;
            SmtpMail.Send(mm);
            TXTFname.Text = "";
            TXTLastName.Text = "";
            TXTMob.Text = "";
            TXTComment.Text = "";
            TXTEmail.Text = "";
            TXTMess.Text = "Thank you for your interest in WBS!!! ";



    }
}

This is what I've come up with through my research:

   public partial class ContactUs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        Calendar cal = new Calendar();
        string dat = cal.TodaysDate.Date.ToLongDateString();

            System.Web.Mail.MailMessage mm = new MailMessage();
            mm.From = "WBS Website<info@wbs.ae>";

    if (DrpDwnType.SelectedItem.Value == "S")
        {
                mm.To = "gavin@wbs.ae";
        }
    else if (DrpDwnType.SelectedItem.Value == "R")
        {
                mm.To = "king@wbs.ae";
        }
    else
        {
                mm.To = "josh@wbs.ae";
        }       

            mm.Cc = "robert@wbs.ae;josh@wbs.ae";
            mm.Bcc = "wolfi@wbs.ae";
            mm.Subject = "Online comments from WBS website visitor, " + TXTFname.Text;
            mm.Body = "<div style='border:solid 2px RED; padding:25px 25px 25px 25px'><br><br> <strong>Online comments from WBS website</strong><br> <br> ------------------------------------- <br> Date : " + dat + "<br> <br> First Name : " + TXTFname.Text + "<br>Last Name : " + TXTLastName.Text + "<br> Email Address : " + TXTEmail.Text + "<br> Contact No : " + TXTMob.Text + "<br> Enquiry Type : " + DrpDwnType.SelectedItem.Text + "<br> <br> <br> The visitor comment : <br> --------------------------------------- <br> " + TXTComment.Text + "</strong><br><br>Further Information : " + RadioButtonList1.SelectedItem.Value.ToString() + "<br><br><br></div>";
            mm.BodyFormat = MailFormat.Html;
            SmtpMail.Send(mm);
            TXTFname.Text = "";
            TXTLastName.Text = "";
            TXTMob.Text = "";
            TXTComment.Text = "";
            TXTEmail.Text = "";
            TXTMess.Text = "Thank you for your interest in WBS!!! ";


    }
}

At this point, this is a mental exercise for me. I may or not attempt to recompile the website without professional help.

** Edit: **

I'm looking to find out if the code I've modified in the second portion will work, and if there is a better way to go about choosing the department that gets mailed based on the selection in the drop down list.

2nd Edit:

Current:

<asp:DropDownList
     ID="DrpDwnType" runat="server" Width="260px" Font-Bold="True">
     <asp:开发者_StackOverflowListItem Value="0">-- select --</asp:ListItem>
     <asp:ListItem Value="G">General                  </asp:ListItem>
     <asp:ListItem Value="S">Service or Workshop</asp:ListItem>
     <asp:ListItem Value="R">Rental Bike</asp:ListItem>
     <asp:ListItem Value="C">Cycling in Dubai</asp:ListItem>
</asp:DropDownList>

New:

<asp:DropDownList
     ID="DrpDwnType" runat="server" Width="260px" Font-Bold="True">
     <asp:ListItem Value="0">-- select --</asp:ListItem>
     <asp:ListItem Value="josh@wbs.ae">General</asp:ListItem>
     <asp:ListItem Value="gavin@wbs.ae">Service or Workshop</asp:ListItem>
     <asp:ListItem Value="king@wbs.ae">Rental Bike</asp:ListItem>
     <asp:ListItem Value="josh@wbs.ae">Cycling in Dubai</asp:ListItem>
</asp:DropDownList>

Then set the mailer to something like:

public partial class ContactUs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            Calendar cal = new Calendar();
            string dat = cal.TodaysDate.Date.ToLongDateString();

                System.Web.Mail.MailMessage mm = new MailMessage();
                mm.From = "WBS Website<info@wbs.ae>";
                mm.To = DrpDwnType.SelectedValue;
                mm.Cc = "robert@wbs.ae;josh@wbs.ae";
                mm.Bcc = "wolfi@wbs.ae";
                mm.Subject = "Online comments from WBS website visitor, " + TXTFname.Text;
                mm.Body = "<div style='border:solid 2px RED; padding:25px 25px 25px 25px'><br><br> <strong>Online comments from WBS website</strong><br> <br> ------------------------------------- <br> Date : " + dat + "<br> <br> First Name : " + TXTFname.Text + "<br>Last Name : " + TXTLastName.Text + "<br> Email Address : " + TXTEmail.Text + "<br> Contact No : " + TXTMob.Text + "<br> Enquiry Type : " + DrpDwnType.SelectedItem.Text + "<br> <br> <br> The visitor comment : <br> --------------------------------------- <br> " + TXTComment.Text + "</strong><br><br>Further Information : " + RadioButtonList1.SelectedItem.Value.ToString() + "<br><br><br></div>";
                mm.BodyFormat = MailFormat.Html;
                SmtpMail.Send(mm);
                TXTFname.Text = "";
                TXTLastName.Text = "";
                TXTMob.Text = "";
                TXTComment.Text = "";
                TXTEmail.Text = "";
                TXTMess.Text = "Thank you for your interest in WBS!!! ";


        }
    }

I hope this kind of question is not too much bother.


I'm not exactly sure what your question is, but if you are asking on how to set different "To" addresses for the message depending on the value of the drop down then it looks like you are on the right path.

I might suggest setting the value of the items in the drop down list and then setting the value of mm.To to that.

<code>
mm.To = DrpDwnType.SelectedValue;
</code>

This might help you avoid a bunch of if statements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜