Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-10-2012, 06:27 PM   PM User | #1
WandaDee
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
WandaDee is an unknown quantity at this point
Email with ASP and HTML form

I'm trying to figure out what I'm doing wronig in getting the form fields to be sent via email.
WandaDee is offline   Reply With Quote
Old 09-10-2012, 10:58 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
No code, no help. This is especially true of sending email from ASP, as there are at least 5 major ways to do so, and I have no clue which one you are using, so I'm not going to try to give 5 answers. Show your code, please.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 09-19-2012, 07:40 AM   PM User | #3
aspiration
New to the CF scene

 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
aspiration is an unknown quantity at this point
This is a dumbed down version of what I use....

sendmail.asp


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Contact</title>

<%
'If the form has not been submitted execute the following code
If Request.Form="" Then %>
<form name="form1" method="post" action="sendmail.asp">
<br><br>
<div align="center">
<table width="75%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#603318">
<td bgcolor="#BB642F"><b>e-mail address</b></td>
<td bgcolor="#BB642F">
<input type="text" name="txtName">
</td>
</tr>
<tr bgcolor="#603318">
<td bgcolor="#9B5226"><b>subject</b></td>
<td bgcolor="#9B5226">
<input type="text" name="txtEmail">
</td>
</tr>
<tr bgcolor="#603318">
<td bgcolor="#BB642F"><b>comment</b></td>
<td bgcolor="#BB642F">
<textarea name="txtFeedback" cols="40" rows="7"></textarea>
</td>
</tr>
<tr bgcolor="#603318">
<td bgcolor="#9B5226">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</div>
</form>

<%
'If the form has been submitted execute the following code
Else

'receive the form values
Dim sName, sEmail, sFeedback
sName=Request.Form("txtName")
sEmail=Request.Form("txtEmail")
sFeedback=Request.Form("txtFeedback")

if sname = "" then
response.write "<br><br><center><h4>You didn't enter your e-mail address."
response.end
end if

if InStr(sname, "@") = 0 or InStr(sname, ".") = 0 then
response.write "<br><br><center><h4>Impropertly formatted email address"
response.end
end if

if semail = "" then
response.write "<br><br><center><h4>You didn't enter a subject."
response.end
end if

if sfeedback = "" then
response.write "<br><br><center><h4>You did not enter any message."
response.end
end if


' create the HTML formatted email text
Dim sEmailText
sEmailText = sEmailText & "<html>"
sEmailText = sEmailText & "<head>"
sEmailText = sEmailText & "<title>HTML Email</title>"
sEmailText = sEmailText & "</head>"
sEmailText = sEmailText & "<body>"
sEmailText = sEmailText & "Subject: " & semail & "<br>"
sEmailText = sEmailText & "Message from: " & sName & "<br>"
sEmailText = sEmailText & "Message:" & sFeedback & "<br>"
sEmailText = sEmailText & "Date & Time:" & Now() & "<br>"
sEmailText = sEmailText & "IP :" & Request.ServerVariables("REMOTE_ADDR")
sEmailText = sEmailText & "</body>"
sEmailText = sEmailText & "</html>"

'create the mail object
Set ObjSendMail = CreateObject( "CDO.Message" )

ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "mail.reliablesite.net"
ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = 25
ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = False
ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" ) = 60

ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = 1 'basic (clear-text) authentication
ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusername" ) ="noreply@ontarioabandonedplaces.com"
ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "password1"
ObjSendMail.Configuration.Fields.Update

ObjSendMail.To = "YOUR_ADDRESS_HERE@hotmail.ca"
ObjSendMail.Subject = semail
ObjSendMail.From = "RETURNEMAIL@YOURADDRESS.com"

' we are sending a text email.. simply switch the comments around to send an html email instead

ObjSendMail.HTMLBody = sEmailtext
ObjSendMail.Send
Set ObjSendMail = Nothing


Response.write "<div align='center'><br><br><font size=3>Thank you for sending your feedback.<br>"

<% End If %> </font>

</html>
aspiration is offline   Reply With Quote
Old 09-20-2012, 12:08 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Looks okay to me.

About the only thing I would change is this line:
Code:
If Request.Form="" Then
I would, instead, specifically use the suibmit button:
Code:
If Trim( Request.Form("Submit") ) = "" Then
But I doubt that really matters.

************

To check that the HTML you are creating is correct, you should add in one DEBUG line:
Code:
...
sEmailText = sEmailText & "</html>"

Response.Write "DEBUG sEmailText:<hr/>" & Replace(sEmailText,"<","&lt;") & "<hr/>"
...
If that debug looks okay, then it must be a problem in the Configuration. And the only people who can help with that would be those at "mail.reliablesite.net", the email service you are trying to use.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 09-20-2012, 12:15 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You know, there MIGHT be something wrong there, more I look at it.

You never actually create the configuration *OBJECT*.

I usually do the two steps separately, like this:
Code:
' first create the configuration object:
Set ObjConfig=CreateObject("CDO.Configuration")
ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2 'Send the message using the network (SMTP over the network).
ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "mail.reliablesite.net"
ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = 25
ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = False 
ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" ) = 60

ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = 1 'basic (clear-text) authentication
ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusername" ) ="noreply@ontarioabandonedplaces.com"
ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "password1"
ObjConfig.Fields.Update


' then create the mail object 
Set ObjSendMail = CreateObject( "CDO.Message" ) 
' and then set the configuration in the message object
Set objSendMail.Configuration=objConfig

...
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:22 PM.


Advertisement
Log in to turn off these ads.