协助提交按钮以发送电子邮件表单数据内容

人气:345 发布:2022-09-22 标签: asp.net c# visual-studio vs2012 ASP.NET

问题描述

好的,为我的公司建立一个小网站并遇到了一个我无法弄清楚的问题。 我有一个表格,其中包含所有文本框已妥善标记。 我已插入上传控件,以便页面访问者可以上传他们的简历。 我有2个按钮,Clear&提交。 清除工作正常。 提交,而不是提交。我希望收集数据并将其发送到电子邮件地址Recruiting@aimsdesigns.com Smtp协议似乎可以让一个人发送电子邮件网站。我需要访问者填写表格并提交,以便将该数据作为电子邮件发送到网站上的地址。 有人可以帮忙吗? 代码段: (HTML)asp.net端 < asp:button id =Hirebuttonrunat =servertext =Hire Meonclick =Hirebutton_Clickxmlns:asp =#unknown/> < asp:button id =ClearButtonrunat =serveronclick =ClearButton_Clicktext =Clearxmlns:asp =#unknown/> 在设计器页面中,双击按钮转到C#侧

OK, building a small site for my company and have ran into an issue, that I cannot figure out. I have a form built which has all the text boxes in place and properly labeled. I have inserted the upload control so that visitors to the page can upload their resume. I have 2 buttons, Clear & Submit. Clear works fine. Submit, not so much. I want the data to be collected and sent to an email address, "Recruiting@aimsdesigns.com" Smtp protocols appear to enable a person to send an email from a website. I need a visitor to complete a form and submit it so that it sends that data as an email to an address on the site. Can anyone help? code segments: The (HTML) asp.net side <asp:button id="Hirebutton" runat="server" text="Hire Me" onclick="Hirebutton_Click" xmlns:asp="#unknown" /> <asp:button id="ClearButton" runat="server" onclick="ClearButton_Click" text="Clear" xmlns:asp="#unknown" /> in the designer page, double click the button to go to the C# side

protected void Hirebutton_Click(object sender, EventArgs e)
{
Try
{
MailMessage msg = New MailMessage();
msg.From = new MailAddress(EmailTxBox.Text);
msg.To.Add(FNameTxtBox.Text, LNameTxtBox.Text, AddressTxBox.Text, CityTxBox.Text,
StateDropDown.Text, PostalCodeTxBox.Text, PhoneTxBox.Text, EmailTxBox.Text, 
ContactDropDown.Text, PositionDropDown.Text, PersonalTxBox.Text);
msg.Subject = "Electric Division Employment";
SmtpClient client = new SmtpClient("");
client.Host = "smtpout.secureserver.net";
client.EnableSsl = true;
System.Net.NetworkCredential = New System.Net.NetworkCredential();
NetworkCredential Username = "Recruiting@aimsdesigns.com";
NetworkCredential Password = "";

client.Port = 25;
client.Credentials = NetworkCredential;
client.Send 
Response.Write("mail send");
}
 
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

这些都不起作用。这就是为什么我之前没有包含它,它是其他东西的指示。就像评论页面或联系我们页面,我认为可行,只需将您想要的信息添加到电子邮件中并发送。 我明显有错误的数据从头到尾,任何人都可以写出我应该使用的代码并将其提交给我,这样我就可以看到它是什么我做得不对?在C#中,一切似乎都在流动,这看起来像是一个混乱。希望解决它并学习更多关于ASP.net开发的知识。谢谢。

None of this works. That is why I didn't include it earlier, it is instructions for something else. Like a comment page or contact us page, that I thought would work, just add the information you want to the email and send it. I clearly have the wrong data in place from beginning to end, can anyone write out the code that I should use and submit that to me so I can see what it is I am not doing correctly? In C# everything seems to flow and this looks like a hatchet mess. Hoping to resolve it and learn a bit more about ASP.net development. Thank you.

推荐答案

你的电子邮件的构造不正确,msg.To似乎填满了邮政地址而不是你想要的地址:招聘@ aimsdesigns.com。将表单数据放在电子邮件正文中。 The construction of your email message is not correct, the msg.To seems to be filled with postal address instead of the to address you want: Recruiting@aimsdesigns.com. Place the form data in the email message body.

你做错了。以下是发送带附件的电子邮件的示例代码: You are doing it wrong. Here is the sample code to send email with attachment:
public static bool SendEMail(string messageFrom, string messageTo, string messageSubject, string messageText)
    {            
        try
        {                
            MailMessage objMailMessage = new MailMessage(messageFrom, messageTo);

            objMailMessage.BodyEncoding = Encoding.UTF8;
            objMailMessage.Subject = messageSubject;
            objMailMessage.Body = messageText;
            Attachment attachedDocument = new Attachment(Server.MapPath("YourDocumentPath"));
            objMailMessage.Attachments.Add(attachedDocument);
            objMailMessage.Priority = MailPriority.High;
            objMailMessage.IsBodyHtml = true;            
            
            System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient("YourIPAddress",PortNumber);
        objSMTPClient.Credentials = new NetworkCredential("UserID", "Password");
            objSMTPClient.Send(objMailMessage);
            return true;                
        }
        catch (Exception ex)
        {
            throw ex;
        } 
    }  

但在调用此函数之前,请将文档上传到某个文件夹,以便存在于附加之前的服务器。

But before calling this function upload your document to some folder so that is s present on the server before being attached.

975