Forum Moderators: open
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.
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.