使用asp页面错误发送邮件

时间:2014-03-31 18:25:01

标签: asp-classic cdo.message

我有一个应该发送邮件的asp页面。我使用下面的代码,但它在发送

时返回错误
<form action="contactus.asp" method="post">
            <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">Name:</div>
            <input type="text" style="width:250px; height:20px;" />
            <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">E-mail Address:</div>
            <input type="text" name="from_mail" style="width:250px; height:20px;" />
            <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">Phone Number:</div>
            <input type="text" style="width:250px; height:20px;" />
            <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">Message:</div>
            <input type="text" name="message" style="width:250px; height:20px;" /> 
            <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">
                <input type="submit" value="Send" style="font-family:Tahoma; font-size:14px; color:green; width:80px; height:20px; font-weight:bold;" />
    </form>
<%
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.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"'Server port
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
%>

1 个答案:

答案 0 :(得分:0)

这应该向您展示如何在脚本中使用表单变量。 asp在你的表单之前,我已经添加了一个条件语句,这样除非按下了Send按钮,否则页面不会尝试执行代码。请注意,我已为发送按钮指定了名称属性

<%  If request.form("Submitbutton") <>"" Then
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From=Request.Form("from_mail")
    myMail.To="someone@somedomain.com"
    myMail.TextBody=Request.Form("message")
    myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
    myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
    myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 
    myMail.Configuration.Fields.Update
    myMail.Send
    set myMail=nothing
    End If
    %>    

<form action="contactus.asp" method="post">
                <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">Name:</div>
                <input type="text" style="width:250px; height:20px;" />
                <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">E-mail Address:</div>
                <input type="text" name="from_mail" style="width:250px; height:20px;" />
                <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">Phone Number:</div>
                <input type="text" style="width:250px; height:20px;" />
                <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">Message:</div>
                <input type="text" name="message" style="width:250px; height:20px;" /> 
                <div style="float:left; padding-left:10px; font-family:Tahoma; font-size:14px; color:green; width:150px;">
                    <input type="submit" name="Submitbutton" value="Send" style="font-family:Tahoma; font-size:14px; color:green; width:80px; height:20px; font-weight:bold;" />
        </form>