Link to home
Start Free TrialLog in
Avatar of apriigem
apriigem

asked on

Sending info from a form to an email address

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. :-)
ASKER CERTIFIED SOLUTION
Avatar of webtrans
webtrans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of webtrans
webtrans

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
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
Avatar of apriigem

ASKER

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!!
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
oh, didn't see your comment
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.
ok try the code and tell me
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using the revised code, the page seemed ok, I didn't get an error message, but then I didn't get an email either.
o kmaybe the server considered it as spam
make it like this
objEMail.To = "apriilgem@verizon.net"
objEMail.From = "apriilgem@verizon.net"
still didnt get the email
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..
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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. :-)
maybe that is the email server
or maybe u did submit twice

but the code as i see is ok
no duplication should occur
What is all you code on the page now?
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>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dude, that totally worked! Thanks!
Great...glad to help!