Solved

Save form in db then automatically send email?

Posted on 2004-10-10
28
257 Views
Last Modified: 2008-02-01
Not sure how to break this down.  

My First question is:

Is it possible to have a user input information, i.e., name and email address into a form - save that form into an access db (this much I am already doing) but then using that information automatically generate an email to the user?

If it helps using dreamweaver, iis, asp, access db and in the end a hosting company.

If it is possible - my Second question would be how?

I don't know how to award this point wise.  The first question -is it possibl? - is what the 50 points is for.

I will up the points for the how to do it part of the question to 500 points - but I guess I need to know if it is possible first - then if it is repost the question.

Hope this makes sense
0
Comment
Question by:avaj
  • 14
  • 12
  • 2
28 Comments
 
LVL 5

Expert Comment

by:waelothman
ID: 12273053
0
 

Author Comment

by:avaj
ID: 12273142
I'm sorry I don't understand.  That would be kind of like aspmail?  The hosting company I use has aspmail.

 What I'm trying to find out is..Is it possible to have input from a user save to a database and generate an instant email automatically during the same post?  - in other words with no manual input involved except the user's initial input on the form.

If the user submits and I post to the database to save the information..then how would I also send the same information to the mail form.
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12273167
i know you just have to write code of sending mail emidiatly after the code insert into database (in same page) and it work
0
 

Author Comment

by:avaj
ID: 12273801
Can it be done with aspmail? Can you be more specific on how?  This is beyond my knowledge and I would be happy to increase points if I can get specific help.

Thanks
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12275672
Whichever asp script your form is posting to you can add the following code to email whoever - obviously you'll have to fill in the values as you see fit:


'Create the e-mail server object
Set objAspEmail = Server.CreateObject("Persits.MailSender")

With objAspEmail
    'Out going SMTP mail server address
    .Host = "yourSMTPmailserveraddress"

    'Who the e-mail is from
    .From = "sender@yourdomain.com"
    .FromName = "You"

    'Who it's being sent to
    .AddAddress "recipient@somewhere.com"
   
    'The subject of the e-mail
    .Subject = "your subject"

    'Email format (TRUE= HTML, FALSE= text)
    .IsHTML = True
   
    'The main body of the e-mail
    .Body = "The email body content"

    'Send it
    If NOT strIncomingMailServer = "" Then .Send
End With

'Close mail object
set objAspEmail = Nothing
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12275713
OOPS - I lied. Hadn't read your post properly - that example code is for the AspEmail component from Persists.
Here's what you're looking for:


    'Create the e-mail server object
    Set objAspMail = Server.CreateObject("SMTPsvg.Mailer")

    With objAspMail
        'Out going SMTP mail server address
        .RemoteHost = "yourSMTPmailserveraddress"

        'Who the e-mail is from
        .FromAddress = "sender@yourdomain.com"
        .FromName = "You"

        'Who its being sent too
        .AddRecipient " ", "recipient@somewhere.com"
 
        'The subject of the e-mail
        .Subject = "Your subject"

        'Email format (TRUE= HTML, FALSE= text)
        .IsHTML = True

        'The main body of the e-mail
        .BodyText = "The email body content"

        'Send it
        .SendMail
     End With

    'Close mail object
    Set objAspMail = Nothing
0
 

Author Comment

by:avaj
ID: 12277491
If the .AddRecipient is coming from the user's input when they enter their email address into the form,  - how would I code the .AddRecipient portion?
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12277947
like this:

dim strRecipient
strRecipient = request.form("email")

.AddRecipient " ", strRecipient





that help?
0
 

Author Comment

by:avaj
ID: 12290413
WhisperUK - I have not forgotten you.  I had some problems with the server and access db - so I had to switch hosts.  It will be a day or so before I can get back to this.  I will try your solution just as soon as they can get me up and running.

Sorry for the delay - I do appreciate your help and will be trying this shortly.

Didn't want anyone to think I have abandoned the question.
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12290583
no worries ;)
Many people dont respond for a lot longer than you. Take yer time
0
 

Author Comment

by:avaj
ID: 12301248
I'm back.  It didn't work.  The form's action sends it to a confirm page which is where I put the code - I've attached the code below.  Also the .IsHtml gave an error of object or property not found (or something like that) so I commented it out just to see if the email would work.

I get no error message - but I also get no email.

The page is fairly small so I posted the entire page.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/connect.inc" -->

<%
FirstName = Request.Form("firstname")
LastName = Request.Form("lastname")
Email = Request.Form("email")
Address = Request.Form("address")
City = Request.Form("city")
State = Request.Form("state")
Zip = Request.Form("zip")

%>      

<%
      cusRS.Open "CustomerInfo",connObj,3,3,2

      cusRS.AddNew

      cusRS("FirstName") = firstname
      cusRS("LastName") = lastname
      cusRS("Email") = email
      cusRS("Address") = address
      cusRS("City") = city
      cusRS("State") = state
      cusRS("Zip") = zip
      
      cusRS.Update
      
      
%>

<%
dim strRecipient
strRecipient = request.form("email")



    '*** send email notice
    'Create the e-mail server object
    Set objAspMail = Server.CreateObject("SMTPsvg.Mailer")

    With objAspMail
        'Out going SMTP mail server address
        .RemoteHost = "mail.designsolutions.com"

        'Who the e-mail is from
        .FromAddress = "info@designsolutions.com"
        .FromName = "DesignSolutions"

        'Who its being sent too
        .AddRecipient " ", "strRecipient"
 
        'The subject of the e-mail
        .Subject = "Coupon"

        'Email format (TRUE= HTML, FALSE= text)
       ' .IsHTML = True

        'The main body of the e-mail
        .BodyText = "Coupon goes here"

        'Send it
        .SendMail
     End With

    'Close mail object
    Set objAspMail = Nothing


%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
A coupon has been sent to your email
</body>
<%
      Set cusRS = nothing
      Set objConn = nothing
%>
</html>
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12302822
And the plot thickens.... hmm can you just adjust your code slightly like below just so you get a message to say what the problem was (if any)

========================================

    '*** send email notice
    'Create the e-mail server object
    Set objAspMail = Server.CreateObject("SMTPsvg.Mailer")

    With objAspMail
        'Out going SMTP mail server address
        .RemoteHost = "mail.designsolutions.com"

        'Who the e-mail is from
        .FromAddress = "info@designsolutions.com"
        .FromName = "DesignSolutions"

        'Who its being sent too
        .AddRecipient " ", "strRecipient"
 
        'The subject of the e-mail
        .Subject = "Coupon"

        'Email format (TRUE= HTML, FALSE= text)
       ' .IsHTML = True

        'The main body of the e-mail
        .BodyText = "Coupon goes here"
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<%
        'Send it
        if  .SendMail then
          Response.Write "<h1>Mail sent</h1>"
        else
           Response.Write "<h1>Mail send failure. Error was " & .Response & " </h1>"
       end if
     End With

    'Close mail object
    Set objAspMail = Nothing
%>
</body>
<%
     Set cusRS = nothing
     Set objConn = nothing
%>
</html>
0
 

Author Comment

by:avaj
ID: 12304524
Okay the error message is.....

Mail send failure. Error was At least one Recipient, CC or BCC must be entered
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12305741
that means that strRecipient could be empty. Make your forum has the attribute :
method="POST"

otherwise the default method will be "GET"  and that will just place the values in the address bar instead of actually posting the form

To check if it's empty change the following line:
Response.Write "<h1>Mail send failure. Error was " & .Response & " </h1>"

TO

Response.Write "<h1>Mail send failure. Error was " & .Response & " </h1>Recipient = " & strRecipient

That should give you the following error message:

"Mail send failure. Error was At least one Recipient, CC or BCC must be entered
Recipient = ???????"

The question marks are the value of strRecipient. It will either be blank or have the email address you entered.

If this doesn't solve your problem could you please post the full code of the form (copy and paste it... dont type)
Thanks,

Whisp


 
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:avaj
ID: 12308828
The message was:

Mail send failure. Error was At least one Recipient, CC or BCC must be entered
Recipient = sssssss

And sssssss was the name I put in...

The code I put above  is the page the form posts to and the form is:

<form  method="post" action="Confirm1.asp" name="form" onsubmit="">
<tr>
      <td align="right" valign="middle" class="text style14"><span class="required  style11">*</span><b>First Name:</b></td>
      <td align="left" valign="middle" class="text"><input type="text" name="firstname" size="25" maxlength="40" class="text"></td>
</tr>
<tr>
      <td align="right" valign="middle" class="text"><span class="required style11">*</span><span class="style15">Last Name:</span></td>
      <td align="left" valign="middle" class="text"><input type="text" name="lastname" size="25" maxlength="40" class="text"></td>
</tr>

<tr>
      <td align="right" valign="middle" class="text style14"><span class="required  style11">*</span><b>Email Address:</b></td>
      <td align="left" valign="middle" class="text"><input type="text" name="email" size="25" maxlength="40" class="text"></td>
</tr>
<tr>
      <td align="right" valign="top" class="text style14"><b>Address:</b></td>
      <td align="left" valign="top" class="text"><input type="text" name="address" size="25" maxlength="40" class="text"></td>
</tr>
<tr>
      <td align="right" valign="top" class="text style14"><b>City:</b></td>
      <td align="left" valign="top" class="text"><input type="text" name="city" size="25" maxlength="40" class="text"></td>
</tr>
<tr>
      <td align="right" valign="top" class="text style14"><b>State:</b></td>
      <td align="left" valign="top" class="text"><input type="text" name="state" size="25" maxlength="40" class="text"></td>
</tr>
<tr>
      <td align="right" valign="top" class="text style14"><b>Zip Code:</b></td>
      <td align="left" valign="top" class="text"><input type="text" name="zip" size="10" maxlength="10" class="text"></td>
</tr>

<tr>
  <td align="center" valign="middle" colspan="2" class="text"></td>
</tr>
<tr>
      <td align="center" valign="middle" colspan="2" class="text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="Submit" name="empty1" class="text"></td>
</tr>
</form>
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12308920
arrgh - just spotted something:

the following line is wrong:
.AddRecipient " ", "strRecipient"

It should read
.AddRecipient " ", strRecipient     ' <----- no quotes around strRecipient


Also if the recients email address is "ssssssss" then I can guarantee that the email aint going anywhere as there is no such address BUT i think that the typing error I pointed out is the reason you're getting the error. The email should just bounce back with a dellivery error, based on the email address "ssssssssssss".
0
 

Author Comment

by:avaj
ID: 12309195
Cool...it worked!  Any chance you would no  why the .IsHtml doesn't work or how/if I can add a giff to the email sent?

ps:  I increased the points as I said I would.
0
 

Author Comment

by:avaj
ID: 12309242
This is the error I get with .IsHtml

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'IsHTML'
0
 
LVL 3

Accepted Solution

by:
WhisperUK earned 500 total points
ID: 12309470
Yep my bad instructions are the reason .IsHtml wont work  :(
I got myself mixed up with the Persists AspEmail component (I always do that... sorry )

Replace that line with:
.ContentType = "text/HTML"

Yes it's possible to add an attachment - see http://www.serverobjects.com/comp/Aspmail4.htm for instructions (I've never used that feature so best refer to the manual on that site)

If you want to send a gif that will display as part of your html, I dont think you can do that. You'll need to host the gif on a website and put the full URL to that image in the <img src="">  in you email html

Hopefully that answers everything - Sorry we didnt get to the resolution quicker. A mixture of me being tired and careless when posting my examples :o/





0
 

Author Comment

by:avaj
ID: 12315180
I went to Aspmail but I didn't see anything that explains how to create the actual body - does Aspmail have the same capabilities as whatever email component experts-exchange uses?  Would like to be able to have a gif and the recipients name in the email - any ideas where I can figure out how to do this - any tutorials you know of?
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12316671
Recipents name if you know it can go in like this:

.AddRecipient "John Smith", "john.smith@johnsmith.com"

And to add an attachment:
.AddAttachment Server.MapPath("/somedir/somepdf.pdf")

And the body (as previously mentioned):
 .BodyText = ""
0
 

Author Comment

by:avaj
ID: 12331195
it's me again..having problem with the body can you go to Q_21171055.html? I went to the documentation for ASPMail but it didn't really help.  I don't want to add an attachment, I would like the gif in the body of the email..
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12331679
I don't think you can actually put the gif in the body of the email.
what you CAN do is host the gif on a web server and put the following in your html code:
<img src="http://www.yoursite.com/yourgif.gif">
0
 

Author Comment

by:avaj
ID: 12332942
Expected end of statement

/Confirm.asp, line 79

.BodyText = "Thank You, " & Request.Form("firstname") <img src="http://www.designsolutions.com/Coupon.gif">
-----------------------------------------------------------^

This is what I get.

0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12333499
change it to
.BodyText = "Thank You, " & Request.Form("firstname") & "<img src='http://www.designsolutions.com/Coupon.gif'>"
0
 

Author Comment

by:avaj
ID: 12334217
That worked!  I wanted you to go to the other posting so I could award you points.  I'm not sure how or if I can from here as the question was already closed?
0
 
LVL 3

Expert Comment

by:WhisperUK
ID: 12334234
which posting?
0
 

Author Comment

by:avaj
ID: 12334255
I think the number is Q_21171055.html
0

Featured Post

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.

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

20 Experts available now in Live!

Get 1:1 Help Now