2014-09-26 100 views
0

我正在與asp的項目工作,我有一個用戶忘記了他或她的密碼,她輸入她的電子郵件的一部分,如果它是有效的,它發送密碼。現在的問題是,它能夠檢查電子郵件是否在數據庫中,併發送郵件,但無法一起發送密碼。發送密碼,如果用戶忘記

<% 

'Check if the form has been processed 
If Request.Form("process")="true" Then 
    'Check the recordset for a valid record 


    If Not rs_user.Eof Then 
    'Valid record, so proceed with the email 
    Call sSendReminder (rs_user("email"), rs_user("password")) 
    Response.Write "Your password has been sent to your inbox. If you don't find it in your mail box, check your junk mail folder" 


    dim sName, sEmail, sMessage 
    dim oCdoMail, oCdoConf, sConfURL 


    sEmail = Request.Form("email") 


     Set oCdoMail = Server.CreateObject("CDO.Message") 
     Set oCdoConf = Server.CreateObject("CDO.Configuration") 

     sConfURL = "http://schemas.microsoft.com/cdo/configuration/" 



     with oCdoConf 
      .Fields.Item(sConfURL & "sendusing") = 2 
      .Fields.Item(sConfURL & "smtpserver") = "smptserveraddress.com" 
      .Fields.Item(sConfURL & "smtpserverport") = 25 
      .Fields.Update 


     end with 

     with oCdoMail 
      .From = "[email protected]" 
      .To = sEmail 
      .Subject = "Password Recovery from samplesite" 
      .TextBody = "Your password is: " & password 
      .HTMLBody = "Your password is: " & password 
      .Configuration = oCdoConf 
      .Send 
     end with 

     Set oCdoConf = Nothing 
     Set oCdoMail = Nothing 


    Else 
    'Not a valid record 
    Response.Write "Sorry, no email was found." 
    End If 
End If 

     Sub sSendReminder(email, password) 

End Sub 

%>

+0

回覆於rs_user( 「密碼」)上面呼叫sSendReminder。你看到價值了嗎? – 2014-09-26 22:18:34

+0

再來。我沒有得到你 – blay 2014-09-26 22:24:55

+0

我現在得到你,與response.write它能夠寫在頁面上的密碼,但不能發送郵件的正文 – blay 2014-09-27 00:30:14

回答

0

是上面的代碼中,你正在運行的確切代碼嗎?

如果是這樣,你需要移動

Sub sSendReminder(email, password) 

上述

dim sName, sEmail, sMessage 

您還需要轉移這些「結束,如果」子外的陳述。

你的代碼運行(我認爲),因爲它在技術上是正確的,但它不像你認爲它應該運行,因爲你的子實際上是空白的。

正確的代碼應該是這樣的:

<% 
 

 
'Check if the form has been processed 
 
If Request.Form("process")="true" Then 
 
    'Check the recordset for a valid record 
 

 

 
If Not rs_user.Eof Then 
 
    'Valid record, so proceed with the email 
 
    Call sSendReminder (rs_user("email"), rs_user("password")) 
 
    Response.Write "Your password has been sent to your inbox. If you don't find it in your mail box, check your junk mail folder" 
 
Else 
 
    'Not a valid record 
 
    Response.Write "Sorry, no email was found." 
 
    End If 
 
End If 
 
\t 
 
\t 
 
\t 
 
Sub sSendReminder(email, password) 
 

 
    dim sName, sEmail, sMessage 
 
    dim oCdoMail, oCdoConf, sConfURL 
 

 

 
    sEmail = Request.Form("email") 
 

 

 
     Set oCdoMail = Server.CreateObject("CDO.Message") 
 
     Set oCdoConf = Server.CreateObject("CDO.Configuration") 
 

 
     sConfURL = "http://schemas.microsoft.com/cdo/configuration/" 
 

 

 

 
     with oCdoConf 
 
      .Fields.Item(sConfURL & "sendusing") = 2 
 
      .Fields.Item(sConfURL & "smtpserver") = "smptserveraddress.com" 
 
      .Fields.Item(sConfURL & "smtpserverport") = 25 
 
      .Fields.Update 
 

 

 
     end with 
 

 
     with oCdoMail 
 
      .From = "[email protected]" 
 
      .To = sEmail 
 
      .Subject = "Password Recovery from samplesite" 
 
      .TextBody = "Your password is: " & password 
 
      .HTMLBody = "Your password is: " & password 
 
      .Configuration = oCdoConf 
 
      .Send 
 
     end with 
 

 
     Set oCdoConf = Nothing 
 
     Set oCdoMail = Nothing 
 
End Sub %>

+0

感謝人,它的工作。耶穌祝福你超出你最瘋狂的想象 – blay 2014-09-27 08:49:15