0
많은 양의 코드를 작성해 드려 죄송합니다.이 양식에 문제가 있습니다. 나는 그것을 구성하는 모든 방법을 시도했지만 단순히 보낼 수 없습니다. 메시지 본문이있는 이메일을 보내면됩니다.하지만 제출할 때마다 오류 (catch 블록에서 오는 오류)가 발생합니다.기본 양식을 제출할 때 SMTP 문제가 발생했습니다.
이것은 C# ASP.NET에 있습니다.
저는 처음 개발에 착수하여 도움을 얻을 수 있습니다. 미리 감사드립니다!
protected void submitButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string messageBody = "//numerous textboxes, dropdown lists, and checkboxes";
SmtpClient smtp = new SmtpClient();
MailMessage message = new MailMessage();
message.IsBodyHtml = false;
try
{
// Prepare to and from e-mail addresses
MailAddress fromAddress = new MailAddress("[email protected]");
MailAddress toAddress = new MailAddress(emailTextBox.Text);
message.From = fromAddress;
message.To.Add(toAddress);
message.Subject = "Contact Form Email";
message.Body = messageBody;
// Server details
smtp.Host = "email.goidp.com";
// Credentials
smtp.UseDefaultCredentials = true;
// Send the email
smtp.Send(message);
// Inform the user
noticeLabel.Visible = true;
noticeLabel.Attributes.CssStyle.Add("display", "block");
//noticeLabel.Text = "E-mail sent";
noticeLabel.Text = "Thank you, we have received your information and will be in touch soon.";
// and clear the form
fullNameTextBox.Text = String.Empty;
companyTextBox.Text = String.Empty;
//many others, this is just to give the idea;
}
catch (Exception ex)
{
errorLabel.Text = "Error sending e-mail:<br/>\n" + ex.Message;
Response.Redirect("estimate-error.html?error=1");
errorLabel.Visible = true;
errorLabel.Attributes.CssStyle.Add("display", "block");
errorLabel.Text = "Error sending e-mail:<br/>\n" + ex.Message;
}
}
else
{
//errorLabel.Text = "Error sending e-mail. Check required fields<br/>";
//Response.Redirect("estimate-error.html?error=2");
errorLabel.Visible = true;
errorLabel.Attributes.CssStyle.Add("display", "block");
errorLabel.Text = "Error sending e-mail. Check required fields<br/>";
}
}
본인은이 사이트가 처음이므로 더 많은 정보를 게시해야합니다. 고맙습니다!
어떤 오류가 발생하고 있습니까? – alf
catch 블록에서 오는 일반적인 오류 일뿐입니다. "이메일을 보내는 중 오류 : 요청을 보내지 못했습니다." – Peter
catch 블록의 첫 번째 줄에 중단 점을 설정하고 예외를 검사 할 수 있습니다. 자세한 정보 또는 내부 예외가 포함되어야합니다. – alf