How to create Contact Us Page in ASP with SMTP Authentication

September 20, 2022Read time:less than a minute read
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Jewelry Design in Chennai | Contact Us | Desigmyjewels.com</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="author" content="@toddmotto">
<link href="css/style.css" rel="stylesheet">
</head>

<body>

<div class="wrapper">
<div id="main" style="padding:50px 0 0 0;">

<!-- Form -->
<form id="contact-form" action="" method="post">
<h3>Get in touch</h3>
<h4>Fill in the form below, and we'll get back to you within 24 hours.</h4>
<div>
<label>
<span>Name: (required)</span>
<input name="txtName" placeholder="Please enter your name" type="text" tabindex="1" required autofocus>
</label>
</div>
<div>
<label>
<span>Email: (required)</span>
<input name="txtMail" placeholder="Please enter your email address" type="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telephone: (required)</span>
<input name="txtPhone" placeholder="Please enter your number" type="tel" tabindex="3" required>
</label>
</div>

<div>
<label>
<span>Message: (required)</span>
<textarea name="txtQuery" placeholder="Include all the details you can" tabindex="5" required></textarea>
</label>
</div>
<div>
<button name="submit" type="submit" id="contact-submit">Send Email</button>
</div>
</form>
<!-- /Form -->

</div>
</div>

<script src="js/scripts.js"></script>

<!-- #include file="send-mail.asp" -->
<%
if Request("txtName")<>"" Then
'Response.write Request.Form() &"<hr>"

strSubject = "Message from designmyjewels.com website!"
strFName = Trim(Request("txtName"))
strPhone = Trim(Request("txtPhone"))
strMail = Trim(Request("txtMail"))
strQuery = Trim(Request("txtQuery"))


strTemplatePath =Server.MapPath(".")
Dim objFile, objStream, strData, strFileLine
set objFile = Server.CreateObject ( "Scripting.FileSystemObject" )

set objStream = objFile.OpenTextFile(strTemplatePath & "\contactmail.fmt")
Do While Not objStream.AtEndOfStream
strFileLine = objStream.ReadLine
strData = strData & vbCrLf & strFileLine
Loop
objStream.Close

strData = Replace(strData, "<name>", request.form("txtName"))
strData = Replace(strData, "<phone>", request.form("txtPhone"))
strData = Replace(strData, "<email>", request.form("txtEmail"))
strData = Replace(strData, "<mesg>", request.form("txtQuery"))


call Send (sEMailFrom, sEmailTo, sCCTo, pstrSubject, strData)

Response.Write("Thank you for writing to us!")
End if
%>

</body>
</html>

Create style.css file

* {
margin:0;
padding:0;
box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-font-smoothing:antialiased;
-moz-font-smoothing:antialiased;
-o-font-smoothing:antialiased;
font-smoothing:antialiased;
text-rendering:optimizeLegibility;
}
body {
font:400 12px/1.625 "Helvetica Neue", Helvetica, Arial, sans-serif;
color:#444;
background:#991D57;
background-image:linear-gradient(left , #761542 0%, #991D57 52%, #761542 100%);
background-image:-moz-linear-gradient(left , #761542 0%, #991D57 52%, #761542 100%);
background-image:-webkit-linear-gradient(left , #761542 0%, #991D57 52%, #761542 100%);
}
.wrapper {
max-width:500px;
width:95%;
margin:0 auto;
position:relative;
}
#contact-form input[type="text"],
#contact-form input[type="email"],
#contact-form input[type="tel"],
#contact-form input[type="url"],
#contact-form textarea,
#contact-form button[type="submit"] {
font:400 12px/12px "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#contact-form {
text-shadow:0 1px 0 #FFF;
border-radius:4px;
-webkit-border-radius:4px;
-moz-border-radius:4px;
background:#F9F9F9;
padding:25px;
}
#contact-form h3 {
color:#991D57;
display:block;
font-size:28px;
}
#contact-form h4 {
margin:5px 0 15px;
display:block;
font-size:13px;
}
#contact-form label span {
cursor:pointer;
color:#991D57;
display:block;
margin:5px 0;
font-weight:900;
}
#contact-form input[type="text"],
#contact-form input[type="email"],
#contact-form input[type="tel"],
#contact-form input[type="url"],
#contact-form textarea {
width:100%;
box-shadow:inset 0 1px 2px #DDD, 0 1px 0 #FFF;
-webkit-box-shadow:inset 0 1px 2px #DDD, 0 1px 0 #FFF;
-moz-box-shadow:inset 0 1px 2px #DDD, 0 1px 0 #FFF;
border:1px solid #CCC;
background:#FFF;
margin:0 0 5px;
padding:10px;
border-radius:5px;
}
#contact-form input[type="text"]:hover,
#contact-form input[type="email"]:hover,
#contact-form input[type="tel"]:hover,
#contact-form input[type="url"]:hover,
#contact-form textarea:hover {
-webkit-transition:border-color 0.3s ease-in-out;
-moz-transition:border-color 0.3s ease-in-out;
transition:border-color 0.3s ease-in-out;
border:1px solid #AAA;
}
#contact-form textarea {
height:100px;
max-width:100%;
}
#contact-form button[type="submit"] {
cursor:pointer;
width:100%;
border:none;
background:#991D57;
background-image:linear-gradient(bottom, #8C1C50 0%, #991D57 52%);
background-image:-moz-linear-gradient(bottom, #8C1C50 0%, #991D57 52%);
background-image:-webkit-linear-gradient(bottom, #8C1C50 0%, #991D57 52%);
color:#FFF;
margin:0 0 5px;
padding:10px;
border-radius:5px;
}
#contact-form button[type="submit"]:hover {
background-image:linear-gradient(bottom, #9C215A 0%, #A82767 52%);
background-image:-moz-linear-gradient(bottom, #9C215A 0%, #A82767 52%);
background-image:-webkit-linear-gradient(bottom, #9C215A 0%, #A82767 52%);
-webkit-transition:background 0.3s ease-in-out;
-moz-transition:background 0.3s ease-in-out;
transition:background-color 0.3s ease-in-out;
}
#contact-form button[type="submit"]:active {
box-shadow:inset 0 1px 3px rgba(0,0,0,0.5);
}
#contact-form input:focus,
#contact-form textarea:focus {
outline:0;
border:1px solid #999;
}
::-webkit-input-placeholder {
color:#888;
}
:-moz-placeholder {
color:#888;
}
::-moz-placeholder {
color:#888;
}
:-ms-input-placeholder {
color:#888;
}


create email template file


<html>
<head>

<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Message from designmyjewels.com </title>
</head>
<link rel="stylesheet" type="text/css" href="style/style.css">
<body>

<div align="left">
<table width="53%" border="0">
<caption >
<p align="left" class="hd_b1">
Message from designmyjewels.com Website</p>
</caption>
<tbody>
<tr>
<td width="37%" valign="top" class="para_blue">
<span style="font-weight: 400">Your Name</span></td>
<td valign="top" width="2%">
:</td>
<td valign="top" width="56%" class="para">
<name></name>&nbsp;</td>
</tr>
<tr>
<td width="37%" valign="top" class="para_blue">
<span style="font-weight: 400">Contact Number</span></td>
<td valign="top" width="2%">
:</td>
<td valign="top" width="56%" class="para">
<phone></phone>&nbsp;</td>
</tr>
<tr>
<td width="37%" valign="top" class="para_blue">
<span style="font-weight: 400">Email</span></td>
<td valign="top" width="2%">
:</td>
<td valign="top" width="56%" class="para">
<email></email>&nbsp;</td>
</tr>

<tr>
<td width="37%" valign="top" class="para_blue">Message </td>
<td valign="top" width="2%">: </td>
<td valign="top" width="56%" class="para"><mesg>&nbsp; </td>
</tr>
</tbody>
</table>
</div>

</body>

</html>

Create send-mail.asp


<%
sEMailFrom="Sender-Email-Address"
sEMailTo="Receiver-Email-Address"
sCCTo="Receiver-Email-Address"
sSMTP="mail.yourdomain.com"
sMailUName="Your-EMail-Address"
sMailPass="Your-Email-Password"


function Send ( pstrFromAddress, pstrToAddress, pstrCCAddress, pstrSubject, pstrMessage )

sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")

' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="[email protected]"
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"

With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = sSMTP
.Item(sch & "smtpauthenticate") = 1
.Item(sch & "sendusername") = sMailUName
.Item(sch & "sendpassword") = sMailPass
.update
End With
Set myMail=CreateObject("CDO.Message")
Set myMail.Configuration = cdoConfig
myMail.Subject=strSubject
myMail.From=pstrFromAddress
myMail.To=pstrToAddress
if len(Trim(pstrCCAddress)) > 0 then
myMail.CC = pstrCCAddress
end if
myMail.HTMLBody = pstrMessage

myMail.Send
set myMail=nothing

End Function

%>

Need Support?

Can't find the answer you're looking for? Don't worry we're here to help!
Contact Support