user2673161
user2673161

Reputation: 1695

ASP Sending Mail

I am a beginner at ASP programming. I am trying to figure out a simple script to send an email. This is my HTML Code:

    <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:

        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? Thank you all in advance!

Upvotes: 1

Views: 474

Answers (1)

Dai
Dai

Reputation: 155085

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.

In VBScript, all objects (i.e. things that aren't numbers or strings) must be assigned using the Set operator. 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.

Upvotes: 1

Related Questions