Hi C# forum,
I need help with a simple script to connect database to email, fogot your password.
I have everything up and running (mail+access database) but putting the two together is new for me!
Ive posted the mailer script and hope some one could help add the data query. much thanks Paul
<%@ Page Language="C#" EnableViewState="false" %>
<script runat="server">
public void Page_Load()
{
// Specify required fields
string[] requiredFields = { "EMAIL", };
// Set the format of the error page
string errorStr;
// errorStr = "Content-type:"text/html \n\n\n";
errorStr = "<?xml version=\"1.0\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
errorStr += "<html>\n<head> <title>ERROR</title></head><do type=\"prev\" label=\"back\"><prev/>\n";
errorStr += "</do><body><center><p>Sorry, you didn't fill the {0} field. Please try again.</p></center></body></html>";
string submitStr;
submitStr = "<?xml version=\"1.0\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
submitStr += "<xhtml>\n<head> <title>MAIL REVEIVED</title> </head><do type=\"prev\" label=\"back\"><prev/>\n";
submitStr += "</do><body><center><p>Thankyou we received your request!</p></center></body></xhtml>";
// Set the format of the email message
string emailStr = "EMAIL: {0}\n";
bool invalidFlag = false;
string returnStr = "";
// Make sure all required fields are present
foreach( string required in requiredFields )
{
if( Request[required] == null || Request[required].Length == 0 )
{
returnStr = String.Format( errorStr, required );
invalidFlag = true;
break;
}
}
if( !invalidFlag )
{
// Create an array to hold the form data
string[] emailData = new string[9];
// Store the form data in the array
emailData[0] = Request["EMAIL"]; // email
// Create the email message
System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();
mailMessage.To = "[email protected]";
mailMessage.From = "FP_Form@.com";
mailMessage.Subject = "Forgot Password";
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text;
// Merge the form data with the email format, and attach it to the email
mailMessage.Body = String.Format( emailStr, emailData );
// Send the email
System.Web.Mail.SmtpMail.SmtpServer = "mail1.server.com";
System.Web.Mail.SmtpMail.Send(mailMessage);
returnStr = submitStr;
}
Response.ContentType = "text/html";
Response.Write( returnStr );
}
</script>