Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp form will not send email

Status
Not open for further replies.

rrmcguire

Programmer
Oct 13, 2010
304
US
I have the below code in my contact_us.asp page, but after fillng out my form on my contact.htm page, my message "Thank you, your registeration has been sent" message appears but the message isn't being sent. Any help would be greatly appreciated as I cannot see what seems to be the problem


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<%
Const cdoSendUsingMethod = "Const cdoSendUsingPort = 2
Const cdoSMTPServer = "Const cdoSMTPServerPort = "Const cdoSMTPConnectionTimeout = "Const cdoSMTPAuthenticate = "Const cdoBasic = 1
Const cdoSendUserName = "Const cdoSendPassword = "
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Dim FirstName, Surname, Email, Message

FirstName = Request.Form("FirstName")
LastName = Request.Form("Surname")
Email = Request.Form("Email")
Message = Request.Form("Message")

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "127.0.0.1"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSMTPConnectionTimeout) = 20
.Item(cdoSendUserName) = "userA@domain.com"
.Item(cdoSendPassword) = "testing"
.Update
End With

Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig

With objMessage
.To = "userB@domain.com"
.From = "userA@domain.com"
.Subject = "YSA Contact Info"
.TextBody = "SMTP Relay Test Send @ " & Now() & vbCrLf & "Surname: " & Surname & vbCrLf & "First Name: " & FirstName & vbCrLf & "Email: " & Email & vbCrLf & "Message: "& Message
.Send

End With

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>

<font size = "8" face = "Arial">"Thank you, your registration has been sent"</font>
</body>
</html>
 
Check for errors before displaying the message.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
 
what do you mean check for errors before displaying the message?

thanks
 
Yep. Check that the return code from mail.send() is 0

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
 
thanks for the reply Chris, where do I go about checking this?

thanks
 
Well, it appears as though its sending, but not displaying anything from my fields in the .TextBody

This is what I currently have for the .TextBody section:

.TextBody = "SMTP Relay Test Send @ " & Now() & vbCrLf & "Surname: " & Surname & vbCrLf & "First Name: " & FirstName & vbCrLf & "Email: " & Email & vbCrLf & "Message: "& Message

any help would be appreciated.

thanks
 
how long does it usually take for SMTP messages to be transferred, its taking almost 5 or 6 hours for mine, or is that dependent on the provider?
 
well, it appears as though my message is sending but when received they come across looking like this:

SMTP Relay Test Send @ 1/31/2011 9:43:11 AM<BR>Surname: Johnson<BR>First Name: Bobb<BR>Email: <a ymailto="mailto:bjohnson@gmail.com" href="mailto:bjohnson@gmail.com">bjohnson@gmail.com</a><BR>Message: ysa registration info<BR><BR>

is there any better way to formoat this?
 
OK, I've made that change, but what is the significance if I have my form with fields FirstName, Surname, Email, and Message then in the section in my asp page with the .HTMLBody where .To and .From are

.To = "bsmith@yahoo.com"
.From = "bsmith@yahoo.com"
.Subject = "YSA Registration"
.HTMLBody = "Registration Form" & Now() & vbCrLf & "Surname: " & Surname & vbCrLf & "First Name: " & FirstName & vbCrLf & "Email: " & Email & vbCrLf & "Message: "& Message
.Send

if when filling out the form with First Name, Surname, Email, etc. why do I need to have .From in the asp script?

 
As it's name implies, .HTMLBody lets you add HTML formatted text to your body. If you use .TextBody, it is just plain text.
 
From" is the From field of the email. "To" is the To field "CC" is the cc field... "Subject" is the subject field, etc. These are the basic fields in any email!
 
but in the script:

.To = "bsmith@yahoo.com".From = "bsmith@yahoo.com".Subject = "YSA Registration" .HTMLBody = "Registration Form" & Now() & vbCrLf & "Surname: " & Surname & vbCrLf & "First Name: " & FirstName & vbCrLf & "Email: " & Email & vbCrLf & "Message: "& Message.Send


why is the .From needed as when filling out the form fields FirstName, Surname, Email, Message, I see that .To is where the message will go to but isn't the .From changing depending on who is filling out the form?
 
I guess I'm just not understanding what you are asking, rrmcguire. the FROM field is whatever YOU set it to be in your code. In your original sample, the FROM is hardcoded to "userA@domain.com". You can set it to whatever you want it to be. These are fields in the CDO.Message object

This has nothing to do with your form fields (FistName, Surname, Email, Message, etc). You would fill the CDO.Message object with values from your form fields, then send the message.

Perhaps, post your code and explain what isn't working, or what part you don't understand
 
basically why is the .From = "userA@domain.com" needed?
 
This question is outside the scope of the ASP forum, and I can't give a very complete answer (although some here can probably explain). Suffice to say, "object.From" is required in CDO.
 
ok, thank you for all of your help..The only other thing Im seeing is taht based off my original script the messages take a long time to deliver to their recipients, i.e. userB@domain.com, would this be dictated by the company who is hosting our pages?

thanks
 
The from header is a required field for most outgoing mails servers and spam filters will usually reject without it.


The time taken to deliver the message will depend on how you are sending it.

Is it going out directly from the server or is it being routed through a mail server?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top