This article demonstrates how to include various user-specified form items in the body of an email message sent by AspEmail.
The idea is to concatenate the text items into a single string and assign this string to the Mail.Body property.For example, a user is asked to fill out the following HTML form and press Submit:
Your name: Your phone: Your email: Which brand interests you: Comments: The content of the form is then sent via email to a sales representative for processing.
The HTML file may look like this:
<FORM ACTION="send.asp" METHOD="POST">
<TABLE BORDER="0" BGCOLOR="#EEEEEE">
<TR><TD>Your name:</TD><TD><INPUT TYPE="TEXT" NAME="user_name"></TD></TR>
<TR><TD>Your phone:</TD><TD><INPUT TYPE="TEXT" NAME="user_phone"></TD></TR>
<TR><TD>Your email:</TD><TD><INPUT TYPE="TEXT" NAME="user_email"></TD></TR>
<TR><TD>Which brand interests you:</TD><TD>
<SELECT NAME="user_brand">
<OPTION>Patek Philippe</OPTION>
<OPTION>Breguet</OPTION>
<OPTION>IWC</OPTION>
</SELECT></TD></TR>
<TR><TD>Comments:</TD><TD><TEXTAREA NAME="user_comments"></TEXTAREA></TD></TR>
<TR><TD COLSPAN="2"><INPUT TYPE="SUBMIT" VALUE="Submit"></TD></TR>
</TABLE>
</FORM>
The underlying ASP script send.asp may look like this:
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "smtp.mycompany.com" ' specify valid SMTP host
Mail.From = "sales@mycompany.com" ' From address
Mail.FromName = "Sales" ' Optional: From nameMail.AddAddress "me@mycompany.com"
' Build message body
Body = "Name: " & Request("user_name") & chr(13) & chr(10)
Body = Body & "Phone: " & Request("user_phone") & chr(13) & chr(10)
Body = Body & "Email: " & Request("user_email") & chr(13) & chr(10)
Body = Body & "Brand: " & Request("user_brand") & chr(13) & chr(10)
Body = Body & "Comments: " & Request("user_comments") & chr(13) & chr(10)Mail.Body = Body ' assign string to Mail.Body
Mail.Send
Note that we use the & operator to concatenate various text items together, and use the combination chr(13) & chr(10) (CR/LF) as a line separator.