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" %>
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 = "\n\n'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
errorStr += "\n
errorStr += "
Sorry, you didn't fill the {0} field. Please try again.
string submitStr;
submitStr = "\n\n'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
submitStr += "
submitStr += "
Thankyou we received your request!
// 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 = "support@.com";
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 );
}
Replies
Know the answer? Post it — somebody with the same question will find it here.