Pull Info from database and send an email

Results 1 to 4 of 4

Thread: Pull Info from database and send an email

  1. #1
    Join Date
    Dec 1969
    Posts
    6

    Default Pull Info from database and send an email

    Hey!<BR><BR><BR><BR>I have another script where i pull all the information from the database and I want to send it to the person. What they do is they enter in their email, and if the email matches, than it will email them their login information. <BR><BR><BR><BR>How do you grab the info and than use that info and put it into an email to send?<BR><BR><BR><BR>Here is my code thus far for it:<BR><BR><BR><BR>&#060;% <BR>Function SendEmail()<BR><BR>Dim myMail<BR>Set myMail = CreateObject("CDONTS.NewMail") <BR>HTML = "&#060;!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN""&#062;" & NL<BR>HTML = HTML & "&#060;html&#062;" <BR>HTML = HTML & "&#060;head&#062;" <BR>HTML = HTML & "&#060;title&#062;Login Information&#060;/title&#062;" <BR>HTML = HTML & "&#060;/head&#062;" <BR>HTML = HTML & "&#060;center&#062;&#060;b&#062;Your Login Information&#060;/b&#062;&#060;/center&#062;"<BR>HTML = HTML & "<BR>Dear: " <BR>HTML = HTML & "<BR><BR>Here is your login information:"<BR>HTML = HTML & "<BR> &#060;b&#062;User Name: &#060;/b&#062;"<BR>HTML = HTML & "<BR> &#060;b&#062;Password: &#060;/b&#062;" <BR>HTML = HTML & "<BR><BR> Please print this page for your records, and keep this information in a safe place. You can always check to see if there are any updates by going to that site. When there is an update available, we will send an email alerting you of this."<BR>HTML = HTML & "<BR><BR> Thank you,"<BR>HTML = HTML & "<BR>3B Software Team"<BR>HTML = HTML & "&#060;/body&#062;"<BR>HTML = HTML & "&#060;/html&#062;"<BR><BR><BR><BR>myMail.From = "a@a.com"<BR>myMail.To = Request.Form("email")<BR>myMail.Subject = "Free Update Login Information"<BR>myMail.BodyFormat = 0 <BR>myMail.MailFormat = 0 <BR>myMail.Body = HTML <BR>myMail.Send <BR><BR><BR>End Function<BR>%&#062;<BR><BR><BR><BR>&#060;%<BR>Resp onse.Expires = -1000 &#039;Make sure the browser doesnt cache this page<BR>Response.Buffer = True &#039;enables our response.redirect to work<BR><BR><BR><BR>If Request.Form("valuepassed") ="true" Then<BR>CheckSignUpForm<BR>Else<BR>ShowSignUpForm< BR>End If<BR><BR>Sub CheckSignUpForm<BR><BR><BR>Dim myconn, verify, blnLoggedIn, email, objRS<BR><BR><BR><BR>Set verify = Server.CreateObject("ADODB.Connection")<BR>verify. open = "Provider=SQLOLEDB.1;Password=XXX;Persist Security Info=True;User ID=XXX;Initial Catalog=XXX;Data Source=XXX"<BR><BR><BR><BR>email = Request.Form("email")<BR><BR>Set objRS = verify.execute("SELECT id,ordernum, firstname, lastname, username, pass FROM regfreeup WHERE email=&#039;" & email & "&#039;;")<BR> If objRS.EOF Then &#039;&#039;&#039;NO RECORDS MATCH. PROCEED WITH LOGIN CREATION<BR> blnLoggedIn = False<BR> Response.Redirect "http://www.microsoft.com"<BR> <BR> Else &#039;&#039;&#039;EVERYTHING PASSED CHANGE EMAIL<BR> blnLoggedIn = True<BR> (no idea how to grab that info and put it into the email up top.)<BR><BR> SendEmail()<BR> Response.Redirect "http://www.yahoo.com"<BR><BR> End If<BR><BR><BR><BR>verify.close<BR>set verify = nothing<BR><BR><BR><BR>ShowSignUpForm<BR>End Sub<BR><BR>%&#062;<BR><BR><BR><BR>&#060;% Sub ShowSignUpForm %&#062;<BR><BR>form<BR><BR>&#060;%end sub%&#062;<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    96,118

    Default The easy way...

    ...would be to simply take the code you have in your SendEMail function and drop it INLINE in your code where you are currently calling the function.<BR><BR>But the alternative is to pass the needed info *TO* the function. (Incidentally, since that so-called function doesn&#039;t return any value, it should be a SUB, instead.)<BR><BR>That is, change to:<BR><BR>SUB SendEMail(email, username, password)<BR>...<BR>END SUB<BR><BR>and then use those values at the appropriate spots in the function. E.g.:<BR><BR>...<BR>HTML = HTML & "&#060;br/&#062;&#060;b&#062;User Name: &#060;/b&#062;" & username <BR>HTML = HTML & "&#060;br/&#062;&#060;b&#062;Password: &#060;/b&#062;" & password<BR>...<BR>myMail.To = email<BR>...<BR><BR>Finally, you have to *PASS* those values TO the Sub.<BR><BR>So change<BR> SendEmail( )<BR>to<BR> SendEmail email, objRS("username"), objRS("pass")<BR><BR>Incidentally, there&#039;s no point in getting fields from the database that you don&#039;t need. So I would expect that you could shorten:<BR><BR>verify.execute("SELECT id,ordernum, firstname, lastname, username, pass FROM regfreeup WHERE email=&#039;" & email & "&#039;;")<BR><BR>down to<BR><BR>verify.execute("SELECT username, pass FROM regfreeup WHERE email=&#039;" & email & "&#039;;")<BR><BR>**********<BR><BR>I do have to say you are pretty nasty to your users! Make ONE mistake in the email address and off they go to Microsoft.com. <BR><BR>And even if they don&#039;t make a mistake you send them to Yahoo?<BR><BR>By the way, *ALL* of this code is a waste of coding:<BR> verify.close<BR> set verify = nothing<BR> ShowSignUpForm<BR>since you are Redirect&#039;ing the user no matter what, and all page processing *stops* as soon as the Redirect is hit.<BR><BR><BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    6

    Default Not nasty

    the redirects to microsoft and yahoo are just test redirects for my internal testing, when i have all of this finalized i will put up the real "error and thankyou" pages (they would be up now, but i havent made em lol) ^_^<BR><BR>Thanks i will try that code out tonight =)

  4. #4
    Join Date
    Dec 1969
    Posts
    96,118

    Default Just FYI...

    ...when I&#039;m testing, I always comment out each Response.Redirect and do something like this:<BR><BR> &#039; Response.Redirect "tryAgain.asp"<BR> Response.Write "&#060;HR&#062;DEBUG: redirect to tryAgain.asp&#060;HR&#062;"<BR> Response.End<BR><BR>To me, it&#039;s a pain to find the browser running off to another page when I thought it wasn&#039;t supposed to. So the debug msg just stops me right on that page. You don&#039;t even have to remove the .Write and .End lines, later. You just uncomment the .Redirect and it&#039;s as if they aren&#039;t there, anyway. So you can easily go back into debug later, if need be.<BR><BR>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •