简体   繁体   中英

CDO.Message not sending mail

Trying to adapt a web form to use CDO.Message. Code was configured previously to use Persits.MailSender and CDONTS.NewMail prior to that. Just can't seem to get it to work despite my tweaks this time around. After filling out the required fields and clicking Send Mail button the page clears itself and only displays the header. No error. No "feedback sent" message. Nothing.

Form is here: http://sverdina.com/feedback.asp . First part does some checking to ensure all required fields are filled etc. This part executes fine. Seems like that what comes next, however doesn't execute.

It's been a while unfortunately so please forgive any obvious coding errors. Any help or suggestions would be much appreciated!

 <%@ LANGUAGE="VBSCRIPT" %> <HTML> <HEAD> <TITLE>sverdina.com - feedback</TITLE> <link rel="stylesheet" type="text/css" href="sverdina.css"> </HEAD> <body bgcolor="696969" link="#ffd700" vlink="#ffd700" alink="#ffd700"> <% Call MenuBar If Request("action") = "send" Then Call SendMail Else Call GetInfo End If Call PageFooter %> </BODY> </HTML> <% Sub SendMail %> <% ErrorStatus = 0 ErrorMessage = "" If Trim(Request("comment")) + "" = "" Then ErrorStatus = 1 ErrorMessage = "Please provide a non-blank comment" ElseIf Request("name") + "" = "" Then ErrorStatus = 2 ErrorMessage = "Please provide a non-blank name" ElseIf Trim(Request("email")) + "" = "" Then ErrorStatus = 3 ErrorMessage = "Please provide a non-blank e-mail address" ElseIf Trim(Request("email")) & "" <> "" and InStr(Request("email"),chr(64)) = 0 Then ErrorStatus = 4 ErrorMessage = "Please enter a valid e-mail address" End If If ErrorStatus > 0 Then %> <form action="feedback.asp" method="post"> <input type="hidden" name="action" value="send"> <br> <FONT FACE="Arial, Helvetica, Verdana" COLOR="red"><b><DIV CLASS="h1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* <%= ErrorMessage %> *</DIV></b></FONT> <br> <FONT FACE="Arial, Helvetica, Verdana" COLOR="gainsboro"> <DIV CLASS="h2_30"> <p>Your Name: <br> <input name="name" size=35 value="<%= Request("name")%>"> <p>Your E-Mail Address: <br> <input name="email" size=35 value="<%= Request("email")%>"> <p>Your Comments: <br> <textarea name="comment" cols=50 rows=7><%= Request("comment") %></textarea> <p><input type="submit" value="Send Mail"> </FONT> </DIV> <br> <DIR> <FONT FACE="Arial, Helvetica, Verdana" COLOR="#ffd700"> <DIV CLASS="h3"> <b>* All fields required</b> </DIV> </FONT> </DIR> </form> <% Else strBody = Request("comment") & Chr(13) & Chr(10) & Chr(13) & Chr(10) strBody = strBody & Request("name") & Chr(13) & Chr(10) & Request("email") & Chr(13) & Chr(10) Set objMessage = CreateObject("CDO.Message") objMessage.From = Request("email") objMessage.Body = strBody objMessage.MailFormat = 1 objMessage.To = "sergio@sverdina.com" On Error Resume Next objMessage.Send Response.Write "<BR><FONT FACE=Arial, Helvetica, Verdana COLOR=gainsboro><DIV CLASS=h4_10b><DIV CLASS=h4_10b><DIV CLASS=h4_10b><p>Feedback Sent.</p></DIV></DIV></DIV></FONT>" set objMessage = nothing End If %> <% End Sub %> <% Sub GetInfo %> <form action="feedback.asp" method="post"> <input type="hidden" name="action" value="send"> <input type="hidden" name="subject" value="Feedback from sverdina,com"> <FONT FACE="Arial, Helvetica: Verdana" COLOR="gainsboro"> <DIV CLASS="h2_30"> <p>Your Name: <br> <input name="name" size=35> <p>Your E-Mail Address: <br> <input name="email" size=35> <p>Your Comments, <br> <textarea name="comment" cols=50 rows=7 ></textarea> <p><input type="submit" value="Send Mail"> </DIV> </FONT> <FONT FACE="Arial, Helvetica; Verdana" COLOR="#ffd700"> <DIV CLASS="h3"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp.<b>*All fields required</b> </DIV> </FONT> </form> <% End Sub %> <% Sub PageFooter %> <.--#INCLUDE FILE="footer.inc"--> <% End Sub %> <% Sub MenuBar %> <!--#INCLUDE FILE="header.inc"--> <% End Sub %>

Figured it out. The "guts" needed to be as follows:

Set objMessage = CreateObject("CDO.Message")
objMessage.Sender =  Request("name")
objMessage.From =  Request("email")
objMessage.TextBody = strBody 
objMessage.To = "sergio@sverdina.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM