I have a file (See below) I use to send mails via contact forms. I have been using the file in Umbrao 4.0, without any problems, but when I apply it in an Umbraco 4.7 installation it doesn't send the form.
Im thinking it must have somthing to do with the way the file is constructed, but I am no .NET expert, so I'm hoping some of you guys can help me out by having a look at the code... Is there any problem with using this code for Umbraco 4.7?
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" +
I have already added the URL to the "umbracoReservedUrls" in the web.config. And I also added the SMTP settings in the config. So what am I missing here??
var smtpMail = new SmtpClient {Host = ConfigurationManager.AppSettings["SMTPHost"]};
try
{
smtpMail.Send(mailMessage);
LoadContactForm(); // This just clears the fields in the form
lblError.Visible = true;
lblError.Text = "Thank you, we will respond to your email ASAP";
}
catch (Exception ex)
{
lblError.Visible = true;
lblError.Text = "Sorry, there has been a problem. Please try again or call us on ";
}
}
You could even set the email addresses as properties in your document type so they can be changed, rather than hard coding them into the config file but depends what you're trying to achieve.
Definitely change the mail format to html rather than UTF8 I think and see if that works.
Problem sending mailform
I have a file (See below) I use to send mails via contact forms. I have been using the file in Umbrao 4.0, without any problems, but when I apply it in an Umbraco 4.7 installation it doesn't send the form.
Im thinking it must have somthing to do with the way the file is constructed, but I am no .NET expert, so I'm hoping some of you guys can help me out by having a look at the code... Is there any problem with using this code for Umbraco 4.7?
--------- MY FILE LOOKS LIKE THIS--------
<%@ Page Language="c#" %>
<%@ Import namespace="System.Web.Mail" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
try
{
string fromName = Request.QueryString["navn"];
string tlf = Request.QueryString["tlf"];
string email = Request.QueryString["email"];
MailMessage msg = new MailMessage();
msg.BodyEncoding=System.Text.Encoding.UTF8;
msg.BodyFormat = MailFormat.Html;
msg.From = email;
msg.To = "[email protected]";
msg.Subject = "Ring mig op, tak";
msg.Body =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" +
"</head><body>" +
"<h3>Forespørgsel:</h3>" + "<br/>" + fromName + "<br/>" + tlf + "<br/>" + email + "<br/>" +
".</html></body>";
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
SmtpMail.SmtpServer = "asmtp.curanet.dk";
SmtpMail.Send(msg);
Response.Redirect("http://www.danskcomputerhjelp.dk/");
}
catch(Exception ex)
{
Response.Write(ex);
Response.Redirect("http://www.danskcomputerhjelp.dk/");
}
}
</script>
<html></html>
----- END OF FILE------
I have already added the URL to the "umbracoReservedUrls" in the web.config. And I also added the SMTP settings in the config. So what am I missing here??
Kind Regards
Mikkel
Oh... and my form looks like this:
-------------------- FORM --------------------
<form class="ringop" action="/sendmail.aspx">
<table>
<tbody>
<tr>
<td class="body" id="navn">
<strong><label for="navn">Dit navn:</label></strong>
</td>
<td>
<input name="navn" class="input" size="20" type="text">
</td>
</tr>
<tr>
<td class="body" id="tlf">
<strong><label for="tlf">Tlf:</label></strong>
</td>
<td>
<input name="tlf" class="input" size="20" type="text">
</td>
</tr>
<tr>
<td class="body" id="email">
<strong><label for="email">Email:</label></strong>
</td>
<td>
<input name="email" class="input" size="20" type="text">
</td>
</tr>
<tr>
<td></td>
<td><input name="submit" class="submitform" value="Submit" type="submit"></td>
</tr>
</tbody>
</table>
</form>
Are you getting an error when doing this or is just not working?
What's the error? If no error, have you stepped through the code to see where it's falling over?
You seem to be hard coding a lot of parameters - is that just for test purposes?
I'm not going to go through each of these, but instead here's something that I'd use:
if (err == false)
{
var to = new MailAddress(ConfigurationManager.AppSettings["FromMailAddress"]);
var from = new MailAddress(ConfigurationManager.AppSettings["MailFromAddress"]);
var mailMessage = new MailMessage(from, to);
mailMessage.Subject = "New email from website contact form";
mailMessage.IsBodyHtml = true;
var mailBody = new StringBuilder();
mailBody.AppendLine("<p>Email from: " + txtName.Text + "</p>");
mailBody.AppendLine("<p>Email Address: " + txtEmail.Text + "</p>");
mailBody.AppendLine("<p>Phone Number: " + txtPhone.Text + "</p>");
mailBody.AppendLine("<p>Enquiry Type: " + Request.Form["enquiry"] + "</p>");
mailBody.AppendLine("<p>Enquiry: " + txtMessage.Text + "</p>");
mailMessage.Body = mailBody.ToString();
var smtpMail = new SmtpClient {Host = ConfigurationManager.AppSettings["SMTPHost"]};
try
{
smtpMail.Send(mailMessage);
LoadContactForm(); // This just clears the fields in the form
lblError.Visible = true;
lblError.Text = "Thank you, we will respond to your email ASAP";
}
catch (Exception ex)
{
lblError.Visible = true;
lblError.Text = "Sorry, there has been a problem. Please try again or call us on ";
}
}
You could even set the email addresses as properties in your document type so they can be changed, rather than hard coding them into the config file but depends what you're trying to achieve.
Definitely change the mail format to html rather than UTF8 I think and see if that works.
But let me know
is working on a reply...