0
我有以下代碼,但它不起作用 - 當我使用message.To
時遇到錯誤,然後我將其更改爲message.To.Add
,但沒有任何成功。帶有文件附件的Asp電子郵件提交
我不知道ASP.net,我只是想讓這件事情起作用。任何幫助表示讚賞。
using System.Net.Mail;
protected void btnsubmit_Click(object sender, EventArgs e)
{
string body = "";
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
body = "<table border='0' align='center' cellpadding='2' style='border-collapse: collapse' bordercolor=''#111111' width='100%' id='AutoNumber1'>";
body = body + "<tr><td width='100%' align='center' colspan='6'><b>Photo Submission Form</b></td></tr>";
body = body + "<tr><td width='100%' colspan='6'> </td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Name</td><td width='50%' colspan='4'><b>" + name.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>E-Mail</td><td width='50%' colspan='4'><b>" + email.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Caption</td><td width='50%' colspan='4'><b>" + caption.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Phone</td><td width='50%' colspan='4'><b>" + phone.Text + "</b></td></tr>";
MailMessage message = new MailMessage();
Attachment myAttachment = new Attachment(FileUpload1.FileContent, fileName);
message.To.Add(new MailAddress("[email protected]"));
message.From = New MailAddress(email.Text);
message.Subject = "Photo Submission Form";
message.BodyFormat = MailFormat.Html;
message.Body = body;
message.Attachments.Add(myAttachment);
SmtpMail.SmtpServer.Insert(0, "");
SmtpMail.Send(message);
RegisterStartupScript("startupScript", "<script language=JavaScript>alert('Message sent successfully.');</script>");
您需要學習C#和ASP ** .Net **。 – SLaks 2011-05-25 19:42:32