?
Solved

Sending info from a form to an email address

Posted on 2004-09-04
25
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
  • 6
25 Comments
 
LVL 5

Accepted Solution

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

Expert Comment

by:webtrans
ID: 11983227
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
ID: 11983797
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:apriigem
ID: 11983892
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
ID: 11983901
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 420 total points
ID: 11983915
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
ID: 11983921
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
ID: 11983927
oh, didn't see your comment
0
 

Author Comment

by:apriigem
ID: 11983946
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
ID: 11983956
ok try the code and tell me
0
 
LVL 5

Assisted Solution

by:webtrans
webtrans earned 420 total points
ID: 11983962
objEMail.From = Request("email")
make it
objEMail.From = "You@yourdomain.com"
0
 

Author Comment

by:apriigem
ID: 11983986
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
 
LVL 5

Expert Comment

by:webtrans
ID: 11983990
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
ID: 11984282
still didnt get the email
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11984490
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
ID: 11988125
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 420 total points
ID: 11988168
add
 & vbcrlf & between the fields
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11988963
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
ID: 11989749
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
ID: 11989823
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
ID: 11991003
What is all you code on the page now?
0
 

Author Comment

by:apriigem
ID: 11998265
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 80 total points
ID: 11998297
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
ID: 12001886
Dude, that totally worked! Thanks!
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12001932
Great...glad to help!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 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