Solved

Sending info from a form to an email address

Posted on 2004-09-04
25
240 Views
Last Modified: 2012-05-05
I am having trouble sending email from form. I keep getting this error message:

Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed

/contact_us.asp, line 97

800401f3
 

This is the script I am using:

<form name="form1" method="post" action="<%=request.servervariables("SCRIPT_NAME")%>">
<input name="uname" type="text" id="uname2">
<input name="email" type="text" id="email2">
<select name="subject" id="subject">
                      <option value="general_question">Question 1</option>
                      <option value="my_site_question">Question 2</option>
                      <option value="pricing_question">Question 3</option>
                    </select>
<textarea name="comments" cols="35" rows="5" id="comments">
<input type="submit" name="Submit" value="Submit">
</form>

<%
If request("submit") = "Submit" Then
  Set objMail = Server.CreateObject("CDONTS.NewMail")
  objMail.From = "sender@address.com"
  objMail.To = "apriigem@verizon.net"
  objMail.Subject = "Message Subject"
  objMail.BodyFormat=0
  objMail.MailFormat=0
  objMail.Body = "User Name: " & request("uname") & "<br>Email:" & request("email") & "Commments: " & request("comments")
  objMail.Send
  Set objMail = Nothing
End If
%>

If anyone could help me figure out how to fix this, it would be great or maybe if someone could offer some easier code that would be great too.  Just so ya now, I am a beginner so please don't make any responses too complicated, my head hurts when I have to think too much. Thanks in advance. :-)
0
Comment
Question by:apriigem
  • 10
  • 9
  • 6
25 Comments
 
LVL 5

Accepted Solution

by:
webtrans earned 105 total points
Comment Utility
ur server does not support CDONTS
maybe it support CDOSYS
ask the server, or check urself
0
 
LVL 5

Expert Comment

by:webtrans
Comment Utility
u could also better use this script
and know for sure which components are on ur server and which are not
http://www.pensaworks.com/prg_com.asp
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
CDO runs on Windows 2003, CDONTs does not.

Here is the code I use:  I wouldn't screw around with the configuration as mentioned...alwasy seems to mess it up.  All default should work fine with your host:

Code below works, I use it: uses port 25, no configuration. Had problem with configuration on local machine.

strTo = "toemail@yourdomain.com"    'Make sure the From field has no spaces.
strFrom = "fromemail@yourdomain.com"
strSubject = "Your Subject"
strBody = "The content of email"


' Create an instance of the NewMail object.
Set objCDOMail = Server.CreateObject("CDO.Message")
   
' Set the properties of the object
objCDOMail.Sender = StrFrom
objCDOMail.To = strTo
objCDOMail.Subject = strSubject
objCDOMail.TextBody = strBody


' Some of the more useful ones I've included samples of here:
'objCDOMail.Cc = "mailto:sschofield@aspfree.com;steve@aspfree.com"   Notice this sending to more than one person!
'objCDOMail.Bcc = "sschofield@aspfree.com;steve@aspfree.com"
'objCDOMail.Importance = 1

'objCDOMail.AttachFile "c:\path\filename.txt", "filename.txt"

' Send the message!
objCDOMail.Send
0
 

Author Comment

by:apriigem
Comment Utility
I found that the server I am using only uses CDOSYS, ASPEMail, JMail and IP Works mail. Using the code you gave me, I get this error:

CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.

/contact_us.asp, line 107

Maybe I have copied it incorrectly or put some stuff in the wrong place. This is what I changed it to:

<% strTo = "info@creativewedsites.com"    'Make sure the From field has no spaces.
strFrom = "info@creativewedsites.com"
strSubject = "Wedsite"
strBody = "The content of email"
Set objCDOMail = Server.CreateObject("CDO.Message")
objCDOMail.Sender = StrFrom
objCDOMail.To = strTo
objCDOMail.Subject = strSubject
objCDOMail.TextBody = strBody
objCDOMail.Send

%>

I would like for the subject of the email to be whatever the user selcts from the form.
Also, I have several different fields in my form. How would I make sure that all that information is in the email? In the previous code I used I had to include all the field names in the code. I don't see that in the revised code you gave me. Help!! I am so lost!!
0
 
LVL 5

Expert Comment

by:webtrans
Comment Utility
http://www.pensaworks.com/prg_com.asp
open the script that u did check the hosting component with
it does send email
and u can use it to find out how it does this (see source code)
and then u would have a working code
:D
0
 
LVL 5

Assisted Solution

by:webtrans
webtrans earned 105 total points
Comment Utility
try the code below also making thenecessary changes

Set objEMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "your@emailaddress.com"
objEMail.From = Request("from")
objEMail.Subject = Request("subject")
objEMail.TextBody = Request("message")  
objEMail.Send
Set objEMail = Nothing
0
 

Author Comment

by:apriigem
Comment Utility
Yeah, I went to that link and I tried that component test thingie and it wouldnt work. I kept getting an error message about using "on error resume next" so I took all that out and it still wouldnt work. I kinda don't understand what I am supposed to be doing with that. I just need some code that works.
0
 

Author Comment

by:apriigem
Comment Utility
oh, didn't see your comment
0
 

Author Comment

by:apriigem
Comment Utility
Used the code below:

<%
Set objEMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "apriilgem@verizon.net"
objEMail.From = Request("email")
objEMail.Subject = Request("subject")
objEMail.TextBody = Request("comments")  
objEMail.Send
Set objEMail = Nothing
%>

and got this:

CDO.Message.1 error '8004020d'
At least one of the From or Sender fields is required, and neither was found.

/contact_us.asp, line 107

I know it's something I didnt do, but what?

also, I have another form I wnat to do the same thing for, but it has multiple fields that should be in the body of the email. How would I include those fields as well.
0
 
LVL 5

Expert Comment

by:webtrans
Comment Utility
ok try the code and tell me
0
 
LVL 5

Assisted Solution

by:webtrans
webtrans earned 105 total points
Comment Utility
objEMail.From = Request("email")
make it
objEMail.From = "You@yourdomain.com"
0
 

Author Comment

by:apriigem
Comment Utility
Using the revised code, the page seemed ok, I didn't get an error message, but then I didn't get an email either.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Expert Comment

by:webtrans
Comment Utility
o kmaybe the server considered it as spam
make it like this
objEMail.To = "apriilgem@verizon.net"
objEMail.From = "apriilgem@verizon.net"
0
 

Author Comment

by:apriigem
Comment Utility
still didnt get the email
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
You should hardcode the email address in the code until you get this to work, and then use request object.  And, sometimes the server will prevent email from being sent to the same domain, and/or the from domain needs to be the ISP domain.  Try a hotmail account or something..
0
 

Author Comment

by:apriigem
Comment Utility
Ok, so i found the code below and this seems to work except I get 2 emails instead of one

<%
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = Request("subject")
objMessage.From = Request("email")
objMessage.To = "info@creativewedsites.com"
objMessage.TextBody = "User Name: " & request("uname")  & "Commments: " & request("comments")
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "sendmail.brinkster.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
%>

does anyone know how I can seperate the body of the email into seperate lines if possible. when i get the email the fields are right next to each other like this:

User Name: Jane doeCommments: sample email
0
 
LVL 5

Assisted Solution

by:webtrans
webtrans earned 105 total points
Comment Utility
add
 & vbcrlf & between the fields
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
Depending on whether you send HTML or Text based:

TEXT - ascii chr()
objMessage.TextBody = "User Name: " & request("uname")  & chr(13) & "Commments: " & request("comments")

HTML:
objMessage.TextBody = "User Name: " & request("uname")  & "<br>Commments: " & request("comments")

And webtrans answer may work as well, but I always use ASCII.
0
 

Author Comment

by:apriigem
Comment Utility
Thanks, that was easy. Ok now, i only have one more thing.
when i try to test the form I get two emails instead of one. When i tested it this morning I got the email that I had just sent, plus the one from last night that I tested. They both went to the email address at the same time. But, if I send one email right after another then I get those 2 seperate emails without a problem. I don't know if I've explained well enough for you guys to understand, but does that make any sense? Is there a solution. Thanks, you guys are super smart...I'm so lucky to have found this place. :-)
0
 
LVL 5

Expert Comment

by:webtrans
Comment Utility
maybe that is the email server
or maybe u did submit twice

but the code as i see is ok
no duplication should occur
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
What is all you code on the page now?
0
 

Author Comment

by:apriigem
Comment Utility
THis is all the code I have on the page now:

<% @ language="VBScript" %>
<% option explicit %>
<% Dim objEMail, objMessage, Confi %>
<html>
<head>
<title>Untitled</title>
<meta http-equiv="Content-Type" content="text/html;">
<!-- Fireworks MX Dreamweaver MX target.  Created Thu Aug 19 00:03:16 GMT-0400 (Eastern Standard Time) 2004-->
</head>
<body bgcolor="#ffffff">
<form name="form1" method="post" action="<%=request.servervariables("SCRIPT_NAME")%>">
              <table width="467" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="202" height="35"><font size="2" face="Arial, Helvetica, sans-serif">Name:
                    </font></td>
                  <td width="265"><input name="uname" type="text" id="uname2"></td>
                </tr>
                <tr>
                  <td height="35"><font size="2" face="Arial, Helvetica, sans-serif">Email
                    Address: </font></td>
                  <td><input name="email" type="text" id="email2"></td>
                </tr>
                <tr>
                  <td height="35"><font size="2" face="Arial, Helvetica, sans-serif">Subject:
                    </font></td>
                  <td><select name="subject" id="subject">
                      <option value="general_question">General comment/question</option>
                      <option value="my_site_question">Question about my site</option>
                      <option value="pricing_question">Question about pricing</option>
                    </select></td>
                </tr>
                <tr>
                  <td height="26" valign="bottom"><font size="2" face="Arial, Helvetica, sans-serif">Comments/Questions:</font></td>
                  <td rowspan="2"><textarea name="comments" cols="35" rows="5" id="comments"></textarea></td>
                </tr>
                <tr>
                  <td height="80" valign="top">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2"><div align="center">
                      <input type="submit" name="Submit" value="Submit">
                    </div></td>
                </tr>
              </table>
            </form></td>
<%
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = Request("subject")
objMessage.From = Request("email")
objMessage.To = "info@creativewedsites.com"
objMessage.TextBody = "User Name: " & request("uname") & vbcrlf & "Commments: " & request("comments")
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "sendmail.brinkster.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
%>


        </tr>
      </table>
      </body>
</html>
0
 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 20 total points
Comment Utility
Change to:

<%
if request("Submit") <> "" then
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = Request("subject")
objMessage.From = Request("email")
objMessage.To = "info@creativewedsites.com"
objMessage.TextBody = "User Name: " & request("uname") & vbcrlf & "Commments: " & request("comments")
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "sendmail.brinkster.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
end if
%>


Was sending twice because it send on default page load...thats waht it appears at least.  The IF statement will check for posting to itself.
0
 

Author Comment

by:apriigem
Comment Utility
Dude, that totally worked! Thanks!
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
Great...glad to help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now