[英]ASP Sending Mail
I am a beginner at ASP programming. 我是ASP编程的初学者。 I am trying to figure out a simple script to send an email.
我试图找出一个简单的脚本来发送电子邮件。 This is my HTML Code:
这是我的HTML代码:
<form method="POST" action="email.aspx">
To <input type="text" name="To"/> <br />
From <input type="text" name="From"/> <br />
Subject <input type="text" name="Subject"/> <br />
Body <textarea name="Body" rows="5" cols="20" wrap="physical" >
</textarea>
<input type="submit" />
</form>
This is my ASP code: 这是我的ASP代码:
Dim mail
mail = Server.CreateObject('CDO.Message')
mail.To = Request.Form("To")
mail.From = Request.Form("From")
mail.Subject = Request.Form("Subject")
mail.TextBody = Request.Form("Body")
mail.Send()
Response.Write("Mail Sent!")
mail = Nothing
I know the set method is no longer supported, I am getting errors with the ASP code, are there any solutions to sending a simple email in ASP? 我知道不再支持set方法,ASP代码出现错误,在ASP中发送简单电子邮件是否有解决方案? Thank you all in advance!
谢谢大家!
Your code will only work if CDO or CDONTS is installed and available on your server - though most webhosts that support Classic ASP will make this available. 仅当CDO或CDONTS已安装并在服务器上可用时,您的代码才有效-尽管大多数支持Classic ASP的Web主机都将使其可用。
In VBScript, all objects (ie things that aren't numbers or strings) must be assigned using the Set
operator. 在VBScript中,必须使用
Set
运算符分配所有对象(即不是数字或字符串的对象)。 It's silly, I know, but this is what you need to do: 我知道这很愚蠢,但这是您需要做的:
Dim mail
Set mail = Server.CreateObject("CDO.Message")
mail.To = Request.Form("To")
mail.From = Request.Form("From")
mail.Subject = Request.Form("Subject")
mail.TextBody = Request.Form("Body")
mail.Send
Response.Write "Mail Sent!"
Set mail = Nothing
If your server doesn't have CDO or CDONTS installed then you'll get an error message when you call CreateObject
, but you haven't listed any error messages in your original question. 如果您的服务器未安装CDO或CDONTS,则在调用
CreateObject
时会收到一条错误消息,但是您没有在原始问题中列出任何错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.