1

我是新来的,不确定我是否正确发布。我为我的网站创建了一个自定义表单,提交后它不会向指定的电子邮件发送电子邮件。我已经搜索并尝试了多种方法来尝试使其正常工作。

我的表格是:

<form name="myForm" action="subform.asp" onSubmit="return validateForm();" method="post">
First Name:<input type="text" size="30" name="fname" maxlength="5"><br>
Last name:<input type="text" size="30" name="lname" maxlength="30"><br>
Email:<input type="text" size="30" name="email" maxlength="30"><br>
Comments:<textarea rows="2" cols="22" name="comments"></textarea>
<input type="submit" value="Submit">
</form>

我的 subform.asp:

<% 
Option Explicit
Dim referer
Dim siteurl
Dim email_from
Dim email_to
Dim strMsg
Dim vsmtpKey

referer = Request.ServerVariables("HTTP_REFERER")
siteurl = "www.mysite.com"
email_from = "email@mysite.com"
email_to = "email@mysite.com"
vsmtpKey = "my key"


strMsg = "First Name : " & request.form("fname") & "<br>" 
strMsg = "Last Name : " & request.form("lname") & "<br>" 
strMsg = "Email : " & request.form("email") & "<br>" 
strMsg = "Comments : " & request.form("comments") & "<br>" 

if InStr(referer, siteurl ) > 0 Then

    Dim HTTPRequest
    Set HTTPRequest = CreateObject("WinHTTP.WinHTTPRequest.5.1")
    HTTPRequest.Open "POST", "http://" & Request.ServerVariables("LOCAL_ADDR") & "subform.asp", False
    HTTPRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    HTTPRequest.SetRequestHeader "Host", Request.ServerVariables("SERVER_NAME")
    HTTPRequest.Send _
        "VsmtpKey=" & vsmtpKey &_
        "&Subject=" & Server.URLEncode("Mailing List Submission") &_
        "&FromEmailAddress=" & email_from &_
        "&ToEmailAddress=" & email_to &_
        "&Body_HTML=" &  Server.URLEncode(strMsg)

    response.write(HTTPRequest.ResponseText)
    Set HTTPRequest = Nothing
End If

%>
4

3 回答 3

0

如果 CDO.Message 在您的服务器上可用,这可能是一个更简单的选择?

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing
%>

代码来自:W3Schools

我建议这样做,因为就设置电子邮件而言,您的代码看起来一切正常,但我从未见过用于使用经典 asp 发送邮件的“WinHTTP.WinHTTPRequest.5.1”类。

如果您必须使用 WinHTTP 方法,我猜您已经检查了对象是否已成功创建,并且您期望的所有数据都存在?如果做不到这一点,会不会是服务器/网络问题阻止了邮件的发送?

于 2014-02-27T10:35:23.170 回答
0

我也为此苦苦挣扎。我尝试和你做类似的事情并最终让它与这个一起工作......(我还必须下载文件 VSMTP_CLASS.asp 并将其通过 FTP 传输到文件夹 /vspfiles - 这是文件所在的位置,代码如下):

emailer.asp test
<!--#include file="VSMTP_CLASS.asp"-->
<% 
Dim mailer 
Set mailer = new vsmtp 
mailer.VsmtpKey = "XXXXXXXXXXXXXX"
mailer.EmailSubject = "Test Subject" 
mailer.EmailFrom = "XXXX@ZZZZZZ.com" 
mailer.EmailTo = "me@mydomainXXXX.com" 
mailer.TextBody = "Hello World!" 
mailer.HTMLBody = "Hello World" 
mailer.Send() 


%>

VSTMP 文件可供下载... https://store.volusion.com/v/vspfiles/manual/kb/VSMTP_CLASS.zip

于 2016-05-20T15:28:41.447 回答
0
HTTPRequest.Open "POST", "http://" & Request.ServerVariables("LOCAL_ADDR") & "subform.asp", False

尝试将“subform.asp”更改为“/vsmtp.asp”,False

于 2016-02-22T07:29:10.897 回答