经典 ASP - 带有附加文件的电子邮件表单 - 请帮忙
我遇到了一个问题,我有一个电子邮件网络表单,可以将输入发送到电子邮件地址,但我现在需要的是一个文件输入字段,用户还可以将图像作为附件发送。
所以联系人姓名、徽标(附件)。
有人告诉我,为了发送附件,需要将其保存在我的主机上的文件夹中,然后才能发送。我已经与托管公司交谈过,他们没有任何措施可以让这变得更容易,例如 aspupload。
以 name="contactname" 和 name="logo" 的形式,我在根目录中有一个名为 logos 的文件夹(此 asp 页面也存在于根目录中)
伙计,我希望有人可以帮助我花了很长时间寻找答案
Dim contactname, logo
contactname = request.form("contactname")
If request("contactname") <> "" THEN
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Form"
myMail.From="web@email"
myMail.To="web@email"
myMail.HTMLBody = "" & contactname & ""
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay.host"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
Ive got abit of a problem ive got an email web form that send the input to an email address but what I now need is a file input field were the user can also send an image as an attachment.
So contact name, logo (attachment).
Ive been told in order to send the attachment it needs to be saved in a folder on my hosting before it can be sent. Ive spoken to the hosting company and they dont have anything in place to make this easier such as aspupload.
In the form name="contactname" and name="logo" I have a folder in the root directory called logos (this asp page also exists in the root directory)
Man I hope someone can help me spent along time looking for answers
Dim contactname, logo
contactname = request.form("contactname")
If request("contactname") <> "" THEN
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Form"
myMail.From="web@email"
myMail.To="web@email"
myMail.HTMLBody = "" & contactname & ""
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay.host"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不能根据从输入字段获取的位置的格式仅使用以下其中一项吗?您不必将其保存到服务器。
Can't you just use one of the following, depending on the format of the location you get from the input field? You shouldn't have to save it to the server.
您需要使用文件输入控件。基本思想是这样声明您的表单:
然后 YourScript.asp 应该使用 ASP Upload 控件将上传的文件存储在服务器上的某个位置,然后使用 CDOSYS 的 AddAttachment 方法。
注意:使用此上传组件时,普通的Request.Form不再可用(由于调用了Response.BinaryRead)。您可以使用此上传控件的 Fields 集合来获取 ContactName 值。
这样的 ASP Upload 控件可以在这里找到:
http://www.asp101.com/ articles/jacob/scriptupload.asp
http ://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=7361&lngWId=4
You need to use a file input control. The basic idea is that you declare your form like this:
YourScript.asp should then use an ASP Upload control to store the uploaded file somewhere on the server, and then use the AddAttachment method of CDOSYS.
Note: When using this upload component, the normal Request.Form is no longer available (due to Response.BinaryRead being called). You can get to the ContactName value by using the Fields collection of this upload control instead.
Such an ASP Upload control can be found here:
http://www.asp101.com/articles/jacob/scriptupload.asp
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=7361&lngWId=4
嗯,是的,如果文件已经存储,我可以使用上述之一,但它没有。该文件来自最终用户的电脑。
因此,他们单击表单中的浏览器并导航到计算机上的文件。我认为需要将其保存到我的主机上的文件中,然后插入文件位置,就像您所做的那样,以便发送它。
erm yeah I could use one of the above if the file was stored already but it not. The file is coming off the end users pc.
So they click browser in the form and navigate to the file on there pc. Which I think then needs to be saved to a file on my hosting then file location inserted kinda like you have done in order for it to be sent.
对于经典的asp,您需要首先以二进制数据形式上传文件:
要以二进制形式上传文件,只需谷歌,您将获得很多经典asp的解决方案。您可以访问:http://www.planet-source-code.com/vb/scripts /ShowCode.asp?txtCodeId=7361&lngWId=4
如果你点击上面的链接,它应该是:
此后,你不需要将二进制数据存储在数据库中。只需创建一个记录集对象,如下所示:
然后您可以创建 CDO 消息对象并继续操作:
这样您无需将上传的文件存储在数据库或服务器空间中。您可以即时附加文件。希望有帮助。
For classic asp you need to first get file uploaded in binary data form:
For getting uploaded file in binary form just google and you shall get a lot of solutions for classic asp.You can go to for : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7361&lngWId=4
If you go by the above link, it shall be:
Thereafter,you need not store the binary data in database.Just create a recordset object as given below:
Then you can create CDO message object and proceed as:
This way you need not store the uploaded file in database or to your server space.You can just attach the file on the fly. Hope it helps.