?
Solved

ASP Mail

Posted on 2006-05-26
11
Medium Priority
?
290 Views
Last Modified: 2012-08-14
Hello,
I am trying to set up an ASP Email on an ASP form; I'm using Dreameaver8, and ASPEmail to send email.  Here is my script to send email. I tested it and it works, but only if it posts to itself. When I set form Action to post it to another page, for example "Confirmation.asp" (<form action="/Confirmation.asp" method="post" name="frmSending">, then it doesn't send out e-mail.  What I want it to do is to send out e-mail at the same time posts to Confirmation.asp when users click submit button on Sending.asp page.  Please let me know if I should provide you guys more detial about the problem. Thanks for any help I can get.
<%
      strHost = "mail.myhost.com"  
      If Request("Send") <> "" Then
            
            Set Mail = Server.CreateObject("Persits.MailSender")
            Mail.Host = strHost

            Mail.From = "myemail@address.com"
            Mail.FromName = "myname"
            Mail.AddAddress Request("To")
            
            Mail.Subject = "subject"
            Mail.Body = Request ("To")

            strErr = ""
            bSuccess = False
            On Error Resume Next ' catch errors
            Mail.Send      
            If Err <> 0 Then ' error occurred
                  strErr = Err.Description
            else
                  bSuccess = True
            End If
      End If
%>
my form code....
....
....
0
Comment
Question by:lazzydog
  • 6
  • 5
11 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16773563
lazzydog,

Put the email script at the beginning of the page confirmation.asp.  You can do both steps you just need to do them one at a time.  If the email steps are the script that is sending.asp then use a response.redirect to go to confirmation.asp at the end of the script.  You could use a line like the one below:

   If Mail.Send then
       Response.Redirect "confirmation.asp"
   Else
       ' code for error
   End if

This is just a general idea.  Let me know which method you need to use if you want more details.  Also let me know if you have any questions.

b0lsc0tt
0
 

Author Comment

by:lazzydog
ID: 16773597
I can not use the E-mail script on the confirmation.asp, for some reason it doesn't like that.  I think because of this line <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%> at the very top of my page. Let me try with Respons.Redirect method on sending page. I'll let you know how it goes.  Thanks.
0
 

Author Comment

by:lazzydog
ID: 16773648
b0lsc0tt,
Can you provide me more detail about using Response.Redirect on Sending.asp page.  Thanks.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16773679
http://www.w3schools.com/asp/asp_ref_response.asp
http://www.w3schools.com/asp/met_redirect.asp

The links above contain some information on the object.  However what was the problem you had?  You should insert the line after you have processed all scripts on that page.  Once the script hits that line it will leave the page.  The page you want to go to is handled as a string so that is why my example is in quotes.

Is the page you want to go to in the same folder as the page that will do the redirecting?  If not then you will need to include path information.  Provide details of the structure and I can help you with this.

The line "If Mail.Send then" may not work with your mail object.  If that is causing a problem then modify it.  The example was trying to redirect only if the mail was sent successfully.  Using the little bit of code you have provided you could also do this ...

          Mail.Send    
          If Err <> 0 Then ' error occurred
               strErr = Err.Description
          else
               bSuccess = True
               Response.Redirect "confirmation.asp"
          End If

If the confirmation page needs to receive variables, etc then you could send them using the URL.  If this information does not help then you will need to provide more information, like the error you are getting, the problem with details and/or the relevant code.  Let me know if you have any questions about this information or need clarification.
0
 

Author Comment

by:lazzydog
ID: 16775661
1. To answer your first question, Is the page you want to go to in the same folder as the page
that will do the redirecting?  Yes it is in the same folder.

2. I tested with the example you provided:
<%
      strHost = "mail.myserver.com"
      If Request("Send") <> "" Then            
            Set Mail = Server.CreateObject("Persits.MailSender")
            Mail.Host = strHost

            Mail.From = "mail@address.com
            Mail.FromName = "myname"
            Mail.AddAddress Request("To")
            
            Mail.Subject = "mysubject"
            Mail.Body = Request ("To")

            strErr = ""
            bSuccess = False
            On Error Resume Next ' catch errors
            Mail.Send      
            If Err <> 0 Then ' error occurred
                  strErr = Err.Description
            else
                  bSuccess = True
                  Response.Redirect ("Confirmation.asp")
            End If
      End If      
%>
With this method, it sends the e-mail, then redirect to the confirmation.asp, which what I wanted BUT, no variable were passed.

You mentioned in the previous comment that "If the confirmation page needs to receive variables, etc then you could send them using the URL." Can you provide me more detail/example how I would do that?

Here is the script for passing variable from my Sending.asp to Confirmation.asp, just incase if you need the info.
This script is in my Confirmation.asp:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
    <%
     var sql_insert, con;
       var LN=new String (Request.Form("CRLastName"));    
con = new ActiveXObject("adodb.connection");
     try{    
con.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=mydatabasepath");
     var repChars="''";
     LN = LN.replace(/\'/g,repChars);
}catch(e){
          Response.Write(e.message);
          Response.End();
     }
     sql_insert = "insert into mytable (CRLastName)values( '" + LN + "')";
     con.Execute (sql_insert);
     con.Close();
     con=null;       

%>

3. I tested it with inserting the E-mail script in Confirmation.asp, so it does one thing at a time(sending, posting, then emailing) and receive this error message:

Microsoft JScript compilation error '800a03ec'

Expected ';'

/EmailConfirmTest.asp, line 181

If Request("Send") <> "" Then
---^

Then I tried it with ";"

If Request("Send") <> "" Then;
still get the same error.

Please let me know if I should provide you more detial about the problem. Thanks.
0
 

Author Comment

by:lazzydog
ID: 16775718
I think the reason I'm getting this error message, because I'm using JavaScript and the e-mail script is in VBScript.  
Microsoft JScript compilation error '800a03ec'

Expected ';'

/EmailConfirmTest.asp, line 181

If Request("Send") <> "" Then
---^
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16785898
You would want to keep the code I provided in the page that uses vbscript.  You could convert the code to use jscript by I'm not an expert in jscript.  What variables do you want passed from sending.asp to confirmation.asp?  I am not sure what you are doing with the javascript code connecting to the database in confirmation.asp.  Since you are using different languages and if the variables were not many and long then you should pass the information as part of the URL (GET method).  This would be the easiest method.  Also any of the languages have a way to get information from the GET portion of the URL.  If you want to tell me the variables and a sample of what they contain then I can be more specific but I have provided a sample below.  It is done on the Response.Redirect line.  The URLEncode method in VBScript will make sure that the information sent in the URL is safe and will work.  In my example I send a name (strName) and email address (strEmail).

   Response.Redirect "confirmation.asp?name=" & Server.URLEncode(strName) & "&email=" & Server.URLEncode(strEmail)

Let me know if you have any questions about this or need more information.
0
 

Author Comment

by:lazzydog
ID: 16790247
In your example:
Response.Redirect "confirmation.asp?name=" & Server.URLEncode(strName) & "&email=" & Server.URLEncode(strEmail)

Are "strName" and "strEmail" your text boxes field names? What about "name" and "email" are those variables need to be declared?

In my case, I would like to pass CRLastName and CRFirstName to Receving.asp, where CRLastName and CRFirstName are my textbox IDs from my Sending.asp. Would the syntax be something like this?


               Response.Redirect "Receiving.asp?name=" & Server.URLEncode(CRFirstName) & "&email=" & Server.URLEncode(CRLastName)

 

0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 600 total points
ID: 16791271
Pretty close!  I would suggest that you change the "name" and "email" in the URL to the names that you want to use for your values.  The URL holds name/value pairs that are seperated by an equals sign (=) and then an ampersand (&) for each set.  You change them to fit what you want the next page to get.  So if you want the next page to get those 2 variables from this page and you want the names to be the same then you would actually use this.

   Response.Redirect "receiving.asp?CRFirstName=" & Server.URLEncode(CRFirstName) & "&CRLastName=" & Server.URLEncode(CRLastName)

The page receiving.asp could then get the variables CRFirstName and CRLastName.  The specifics of how to get a variable from the querystring/URL would depend on the language but in ASP(VBScript) you would use this on receiving.asp.

CRFirstName = Request.QueryString("CRFirstName")
CRLastName = Request.QueryString("CRLastName")

The part of the URL that passes this information is referred to as the querystring.  You can look here (http://en.wikipedia.org/wiki/Query_string) or search the web for more info if you want.

Let me know if you have a question about this.  I hope this has got your code working!

bol
0
 

Author Comment

by:lazzydog
ID: 16794834
Thanks Bol for your help.  
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16803366
Your welcome!  Thank you for the grade, the points and the fun question.

bol
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question