I am a PHP Developer and I do not have any knowledge about ASP. Sadly I am the only developer here and a client had ASP (not ASP.NET) pages and they wanted a “Contact Us” Form.
I searched the internet to find out how to serve ASP files in Apache and it pointed me to mod_aspdotnet. It was so stupid of me to think that ASP is the same as ASP.NET! Now do you see my problem? I have developed a working ASP.NET email script. The files had .aspx extensions but the actual site had .asp extensions, they were using ASP and not ASP.NET!
So I would like to ask for help. This is my email script:
<%@ Page Language="VB" Debug="true" %>
<%@Import Namespace="System.Web.Mail" %>
<script language="vb" runat="server">
Sub Send2Mail (sender as Object, e as EventArgs)
Dim objMail as New MailMessage()
if Logo.HasFile Then
Try
Logo.SaveAs(Server.MapPath("uploads/") + Request.form("strName") + "_Logo_" + Logo.FileName)
objMail.Attachments.Add(new MailAttachment(Server.MapPath("uploads/" + Request.form("strName") + "_Logo_" + Logo.FileName)))
Catch ex As Exception
msg.Text = "<b>The Logo could not be uploaded</b>. The following error occured: <i>" + ex.Message + "</i><br />"
msg.Visible = true
end try
end if
if Image1.HasFile Then
Try
Image1.SaveAs(Server.MapPath("uploads/") + Request.form("strName") + "_Image1_" + Image1.FileName)
objMail.Attachments.Add(new MailAttachment(Server.MapPath("uploads/" + Request.form("strName") + "_Image1_" + Image1.FileName)))
Catch ex As Exception
msg.Text = "Image 1 could not be uploaded. The following error occured: <i>" + ex.Message + "</i><br />"
msg.Visible = true
end try
end if
if Image2.HasFile Then
Try
Image2.SaveAs(Server.MapPath("uploads/") + Request.form("strName") + "_Image2_" + Image2.FileName)
objMail.Attachments.Add(new MailAttachment(Server.MapPath("uploads/" + Request.form("strName") + "_Image2_" + Image2.FileName)))
Catch ex As Exception
msg.Text = "Image 2 could not be uploaded. The following error occured: <i>" + ex.Message + "</i><br />"
msg.Visible = true
end try
end if
objMail.To = "example@example.com"
objMail.From = """Us"" <do-not-reply@foo.com>"
objMail.BodyFormat = MailFormat.Html
objMail.Priority = MailPriority.Normal
objMail.Subject = "Business Registration"
objMail.Body = "<html><body style='font-family: Verdana'><table style='font-family: Verdana; font-size: 11px'>"
objMail.Body += "<tr><td><b>Business Name:</b></td><td>" + Request.form("strName") + "</td></tr>"
objMail.Body += "<tr><td><b>Opening Business Description:</b></td><td>" + Request.form("strOpenDesc") + "</td></tr>"
objMail.Body += "<tr><td><b>Opening Hours:</b></td><td>" + Request.form("strHours") + "</td></tr>"
objMail.Body += "<tr><td><b>Business Description:</b></td><td>" + Request.form("strBusDesc") + "</td></tr>"
objMail.Body += "<tr><td><b>Servicing Area:</b></td><td>" + Request.form("strService") + "</td></tr>"
objMail.Body += "<tr><td><b>Website Address:</b></td><td>" + Request.form("strWebsite") + "</td></tr>"
objMail.Body += "<tr><td><b>Email Address:</b></td><td>" + Request.form("strEmail") + "</td></tr>"
objMail.Body += "<tr><td><b>Telephone Number:</b></td><td>" + Request.form("strPhone") + "</td></tr>"
objMail.Body += "<tr><td><b>Fax Number:</b></td><td>" + Request.form("strFax") + "</td></tr>"
objMail.Body += "<tr><td><b>Mobile Phone Number:</b></td><td>" + Request.form("strMobile") + "</td></tr>"
objMail.Body += "<tr><td><b>Suburb / Post Code:</b></td><td>" + Request.form("strPostCode") + "</td></tr>"
objMail.Body += "<tr><td><b>Proprietor Name:</b></td><td>" + Request.form("strPropName") + "</td></tr>"
objMail.Body += "<tr><td><br /></td></tr>"
objMail.Body += "<tr><td><b>Image 1 Caption:</b></td><td>" + Request.form("strImage1Caption") + "</td></tr>"
objMail.Body += "<tr><td><b>Image 2 Caption:</b></td><td>" + Request.form("strImage2Caption") + "</td></tr>"
objMail.Body += "</table><body></html>"
SmtpMail.SmtpServer = "localhost"
Try
SmtpMail.Send(objMail)
strMessage.Visible = true
Catch ex As Exception
msg.Text = "<b>The message was not sent</b>. The following error occured: <i>" + ex.Message + "</i><br />"
msg.Visible = true
End Try
End Sub
Will this work in ASP as it is? What do I need to change to make it work in ASP? I am also using the <asp:></asp:> tags. Will this work in ASP?
EDIT
I am sorry for the confusion of what server I am using for development and the host server. The host is using IIS. I am using Apache because I am really a PHP developer. The problem about running ASP pages in Apache was because the client does not want to give me access to their server. They told me that I should just deliver the files.
ASPandASP.NETshare names for pure marketing reasons but they are basically unrelated technologies, although the latter reuses concepts (such as being a language agnostic framework) and even some method names (such asServer.MapPath).In both ASP’s, you have to pick a supported programming language and code your scripts with it. Your sample code seems to use VisualBasic, which was not supported by classic ASP. You’ll have to switch to (e.g.) VBScript. Unlike VisualBasic, VBScript is loosely typed, but apart from that it has a similar syntax.
The classic ASP way to send e-mail is the CDONTS library. A simple example:
In general, classic ASP was very similar to PHP: you embed code in your HTML documents.
The difficult part is file upload handling. ASP did not have a native file upload feature: you had to purchase and install a binary commercial library or find one of the VBScript-only code snippets available at the Internet.
Edit: Does your client really run ASP over Apache? Microsoft only supports IIS. Apache modules for ASP were normally written by third-parties and often implemented different languages like Perl.