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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please can someone check my code

Status
Not open for further replies.

TonyU

Technical User
Feb 14, 2001
1,317
US
[tt]I have this form that is suppossed to send an email after submitting it but it's not working. the "Thank you for your comment! An email has been sent to you." is displayed after submitting, but no email is delivered and I don't see the problem nor do I get an error.


[tt]
Here's my code
<%@language = vbscript%>
<%option explicit%>
<%
dim name, email, query
name = request.form(&quot;name&quot;)
email = request.form(&quot;email&quot;)
query = request.form(&quot;query&quot;)

if (name <> &quot;&quot; and email <> &quot;&quot; and query <> &quot;&quot;) then
dim objmail, recipients
set objmail = server.createobject(&quot;cdonts.newmail&quot;)

objmail.from = &quot;WebMaster@MyCompany.com&quot;
objmail.to = email
objmail.subject = &quot;Your Inquiry&quot; & name
recipients = array(&quot;me@mycompany.com&quot;, _
&quot;me@mycompany.com&quot;)
objmail.bcc = Join(recipients, &quot;;&quot;)
objmail.body = query
objmail.send
response.write &quot;Thank you for your comment! An email has been sent to you.&quot;
set objmail = nothing
else
%>

[tt]And here's the form:

<FORM name=&quot;form1&quot; method=&quot;post&quot; action=&quot;<%=request.servervariables(&quot;script_name&quot;)%>&quot;>
<P>Name
<INPUT type=&quot;text&quot; name=&quot;name&quot; size=&quot;40&quot;>
</P>
<P>Email
<INPUT type=&quot;text&quot; name=&quot;email&quot; size=&quot;40&quot;>
</P>
<P>Query/Questions
<textarea name=&quot;query&quot; cols=40 rows=10></textarea>
</P>
<P>
<input type=submit value=&quot;submit&quot;>
</P>
</FORM>




[/tt]
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
1. make sure that the SMTP server is running.
2. take out the &quot;On Error Resume Next&quot; in the page (if you have it) to see if there is any error messages.

 
If you continue to have difficulty, try a mailer object I have used often:


Here is a sub I have used:

Public Function sendMail(ByVal sender$, ByVal receiver$, ByVal blindCopy$, ByVal subject$, ByVal body$, ByVal mailHost$) As Boolean
Dim mailer As SASMTPLib.CoSMTPMail
Set mailer = CreateObject(&quot;SoftArtisans.SMTPMail&quot;)
Set mailer = New SASMTPLib.CoSMTPMail
With mailer
.FromName = sender$
.FromAddress = sender$
If blindCopy$ <> &quot;&quot; Then
.AddBCC &quot;&quot;, blindCopy$
End If
.AddRecipient &quot;&quot;, receiver$
.BodyText = body$
.DateTime = Date
.subject = subject$
.SMTPLog = App.path & &quot;\samail.log&quot;
.RemoteHost = mailHost$
.WordWrap = True
.Priority = NORMAL_P
End With
If mailer.sendMail Then
sendMail = True
Else
sendMail = False
End If
Set mailer = Nothing
End Function

It will not authenticate to an outside server (not the free version), but if the ASP page is on the same machine, you should have no problem. Hope that helps. Jonathan Galpin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top