form mail

I need form mail that will work with the server.  Can anyone help?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

couldnt you not use CDO?

Dim sFrom, sTo, sCC, sBCC, sSubject, sBody

sFrom = ""
sTo = ""
sCC = ""
sBCC = ""
sSubject = "Here's the test email!"
sBody = "Hello!" & vbCrLf & vbCrLf & _
              "I hope you're having a great day!" & vbCrLf & vbCrLf & _
Call SendEmail(sFrom, sTo, sCC, sBCC, sSubject, sBody)

Function SendEmail(sFrom, sTo, sCC, sBCC, sSubject, sBody)
  Dim MyMail
  Set MyMail = Server.CreateObject("CDONTS.NewMail")
  MyMail.From = sFrom
  MyMail.To = sTo
  MyMail.Cc = sCC
  MyMail.Bcc = sBCC
  MyMail.Subject = sSubject
  MyMail.Body = sBody
  Set MyMail = Nothing
end function
thats CDONTS for NT systems, for cdo change this:

 Set MyMail = Server.CreateObject("CDONTS.NewMail")

to this:

Set myMail=CreateObject("CDO.Message")
then just use a form and ASP to get the values you want in there, is this what your after?
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

brycol24Author Commented:

To be honest I'm not sure what I'm after.  I just need form mail script that can be used on a web page so when someone fills out that mail form it will be sent to my e-mail...Is that the code you gave me?
yeh it is, you just create an HTML form with fields you need and then put the code above in an ASP page and request.form the values from the form and store them in variables and refer to the variables in the code above, for example for the email:

dim FROMemail
FROMemail = request.form("Useremail")


MyMail.From = FROMemail
myMail.To = ""
brycol24Author Commented:

I can't save the page as an HTM page but it has to be ASP?

yeh, its has to be an asp page to be able to send mail.
Have your form look like this(emailform.htm):

<title>Email form</title>

<form method="post" action="sendmail.asp">
      <td>Your Name:</td>
      <td><input type="text" name="username"></td>
      <td>Your Message:</td>
      <td><input type="text" name="message"></td>
      <td><input type="submit" value="Send Email"></td>



And have your ASP page look like this(sendmail.asp):

Dim username
Dim usermsg

username = request.form("username")
usermsg = request.form("message")

If len(trim(username))>0 Then

      Dim sfrom, sto, scc, sbcc, sSubject, Sbody

      sfrom = username
      sto = ""
      scc = ""
      sbcc = ""
      sSubject = "Email from " & username
      Sbody = Message
   Call Sendmail(Sfrom, Sto, Scc, Sbcc, Ssubject, sbody)

   function Sendmail(Sfrom, Sto, Scc, Sbcc, Ssubject, sbody)
      Dim MyMail
      Set MyMail = server.createobject("CDO.message")
      MyMail.From = sfrom
      MyMail.To = sTo
      MyMail.Cc = sCc
      myMail.bcc = Sbcc
      MyMail.Subject = Ssubject
      MyMail.textbody = sbody
      Set MyMail = nothing
   End Function
      response.write "You did not enter a valid Name, click " & "<a href=""emailform.htm"">HERE</a>" & " to go back and reattempt to send a mail<br>thank you"
End If

Try that out, remember this will only work with Win 2000 or later as otherwise you would use CDONTS and not CDO
Hey brycol24-

Your host is If so, which hosting plan are you under?
It appears that unless you have the "Web Hosting with eCommerce" you'll be limited to PHP or Perl.
Ok if your limited to PERL Here is a basic script you can try out (Note this is using seperate HTML Page and a PERL Script- they could be combined but im gunna try keep this simple for ya)

replace the {stuff in these} with the actual locations / variables

{Your form elements here- ENSURE THAT EACH HAS A NAME Property i.e.
<INPUT TYPE="Text" NAME={Name Goes Here}>

This will need to be saved in your cgi-bin or a special PERL area check your host for details
{Path to perl*}

#Use the CGI module that handles form input
use CGI qw/:standard/;

#read your data from the form
#Using scalar variables for simplicity
#NOTE: You should replace these with meaninfull
#names and replace the values in param with your
#OWN field names (you specified them in the form)
#etc etc

#Print a content type to allow output
print "Content-Type: text/html\n\n";

#once the values are read in- send the email
if (open(MAIL, "|/usr/bin/mini-sendmail -t")) {

#replace these with the email address you want to send to aswell as
#the address you want it to appear to come from
print MAIL "To: You@Email.Address\nFrom: You@Email.Address\n";

#Change the subject here if you wish
print MAIL "Subject: Web Form Data\n";

#again alter these to fit your form
print MAIL "Value 1: $var1 \n Value 2: $var2";


print <<"HTML Code";

email dispatched<BR>

} else {
print "error while sending email";

*PathTo Perl
Check with your webhost usually #!/usr/bin/perl or #!/usr/lib/bin/perl

note i havnt tested that code- any problems let me know

If you havnt used perl before the message INTERNAL SERVER ERROR usually means you have a syntax error - double check you typed your stuff correctly if it doesnt work post your customized code

Also note you need to change the permissions (CHMOD) of PERL files to 755 for them to be executable

Hope that helps


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sorry forgot to add that you need to check with your server the path to sendmail and update this line as appropriate:

#once the values are read in- send the email
if (open(MAIL, "|/usr/bin/mini-sendmail -t")) {
                            YOUR SENDMAIL PATH HERE
Thanks for the points- Were you able to adapt the code ok?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.