Forum Moderators: open

Message Too Old, No Replies

ASPMAIL: Response.Redirect Problems

         

thewinchester

3:30 am on Apr 6, 2003 (gmt 0)



Okies, i'm a little stuck with the Response.Redirect object when processing a form with Aspmail.

I've been searching the web for a few examples and it suggests that Response.Redirect should be placed after the if Mailer.Sendmail then line.

Example of code:

======
<%
Set Mailer= Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = Request.Form("txtName")
Mailer.FromAddress= Request.Form("txtEmail")
Mailer.RemoteHost = "--------"
Mailer.AddRecipient "--------"
Mailer.Subject = "Web Enquiry"

Mailer.Priority = 2

strMsgHeader = "The following enquiry has been submitted by " & Request.Form("txtName") & " via the Apollo Website." & vbCrLf & vbCrLf & "Submitted information as follows:" & vbCrLf & vbCrLf
for i = 1 to Request.Form.Count
strMsgInfo = strMsgInfo & Request.Form.Key(i) & " - " & _
Request.Form.Item(i) & vbCrLf
next
strMsgFooter = vbCrLf & "End of Submission"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter

Mailer.DateTime = WeekDayName(WeekDay(Date), true) & _
", " & Day(Date) & " " & MonthName(Month(Date), true) & _
" " & Year(Date) & " " & FormatDateTime(Now, 4) & " +0800 (WST)"
Mailer.SendMail

if Mailer.SendMail then
response.Redirect("http://www.apollobearings.com.au/thankyou.asp")
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
%>
======

However, when I am submitting the form it returns the following error:

======
Response object error 'ASP 0156 : 80004005'

Header Error

/scripts/aspmail.asp, line 40

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
======

Any pointers as to what I am doing wrong would be appreciated.

pterodactyl

8:11 am on Apr 6, 2003 (gmt 0)

10+ Year Member



Is this code contained inside <html> tags?

Response.Redirect needs to be called before any <html> is written.

bmcgee

3:56 am on Apr 30, 2003 (gmt 0)

10+ Year Member



At the very top of the ASP page, put in a:
<%Response.Buffer = True%>

This will stop the error you are getting from rearing its ugly head. Note that this line keeps anything from being sent to the client until the page is fully ready to go, or until you explicity call a Response.Flush to dump out the page to that point.