Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really Basic Question About Scripting

Status
Not open for further replies.

dbrooks74

Programmer
Nov 13, 2001
105
US
I think I am missing something really obvious. I have a need to call an email script from vbscript. Everytime I write vbscript I always start it with...

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--
Sub MyFunction()

End Sub
-->
</SCRIPT>

However the email script does not have the <!-- it has the <% around them as seen below...

<%
Set mySmartMail = Server.CreateObject(&quot;aspSmartMail.SmartMail&quot;)
mySmartMail.Server = &quot;EmailServer&quot;
mySmartMail.SenderName = &quot;Task User&quot;
mySmartMail.SenderAddress = strMyEmailAddress
mySmartMail.Recipients.Add sEmailAddress, &quot;Task User&quot;
mySmartMail.Subject = strSubjectLine
mySmartMail.Body = &quot;<b>Test Email</b>&quot;
mySmartMail.SendMail
%>


Each of these work seperately but when I try to put them together like this...
<SCRIPT LANGUAGE=&quot;VBScript&quot;>

<!--
Sub MyFunction(strMyEmailAddress)
<%
Set mySmartMail = Server.CreateObject(&quot;aspSmartMail.SmartMail&quot;)
mySmartMail.Server = &quot;EmailServer&quot;
mySmartMail.SenderName = &quot;Task User&quot;
mySmartMail.SenderAddress = strMyEmailAddress
mySmartMail.Recipients.Add sEmailAddress, &quot;Task User&quot;
mySmartMail.Subject = strSubjectLine
mySmartMail.Body = &quot;<b>Test Email</b>&quot;
mySmartMail.SendMail
%>
End Sub
-->

Does anyone know how I can make this work? Thanks for you help.
 
The <script language=&quot;vbscript&quot;> code is client-side VB.

The email function (with the <%...%> around it) is ASP code and is processed on the server before the page is sent to the client.

You cannot call the ASP function from the client-side code because once the page is sent, that function does not theoretically exist!

Can you explain a bit more about what you are trying to do on your page? Have you got a button or something that a user clicks and it sends the mail?
 
I have an OnClick event for a button that takes that information from an input box, which is &quot;Please enter an email address:&quot; and tries to send an email. Since I do not know how to send an email from vbscript I was using ASP to send a server email object called &quot;MySmartMail&quot; to send an email to the user specified.

So I need to somehow call the ASP code from my vbscript code.

Thanks for all of your help, and ideas would be appreciated.
 
You are correct in using ASP to send the email. You just need to submit the form to get the email address into the email function.

So you have one page (input.htm) which has this kind of thing:

Code:
<form name=&quot;form1&quot; action=&quot;sendmail.asp&quot; method=&quot;post&quot;>
Enter email: <input type=&quot;text&quot; name=&quot;txtEmail&quot; size=&quot;30&quot;>
<input type=&quot;submit&quot; value=&quot;Send mail!&quot;>
</form>

This sends the form fields to the next page (sendmail.asp) which processes and sends the mail:

Code:
<%
Dim sEmailAddress
sEmailAddress = Request.Form(&quot;txtEmail&quot;)

Set mySmartMail = Server.CreateObject(&quot;aspSmartMail.SmartMail&quot;)
mySmartMail.Server = &quot;EmailServer&quot;
mySmartMail.SenderName = &quot;Task User&quot;
mySmartMail.SenderAddress = strMyEmailAddress
mySmartMail.Recipients.Add sEmailAddress, &quot;Task User&quot;
mySmartMail.Subject = strSubjectLine
mySmartMail.Body = &quot;<b>Test Email</b>&quot;
mySmartMail.SendMail
%>

(I've not used SmartMail before so I've just copied your original script for that part!)

You can then add extra fields to the form to allow your user to specify subject etc..
 
I thought I was going to have to redirect the browser to another page. Thanks for all of your help, I will do that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top