Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format asp send email

Status
Not open for further replies.

tonyx666

MIS
Apr 13, 2006
214
GB
ok, i have a question, there is a fair bit of code in this post.. i dont expect someone to trail through all of it and give me the complete solution.. i would appreciate however if someone could show me a single example.. and i think i can do the rest..

basically, i have a html template.. with tables..

and i want that template to be sent to me.. with the details filled in from my website form..

i have the html code template.. and i have the code that emails the details..

the email at the moment simply sends the details like so..

Date: this
To: this
From: this

etc

i want the values to be put in the template and have that template emailed to me..

below is the asp send mail code. and below that is the html template..

once again. any help on how to get the syntax correct is all i need..

the send mail code
Code:
<% @LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head> 
<body> 
 

<% 

Set Mail = Server.CreateObject("SMTPsvg.Mailer")
Mail.FromName   = "London Heathrow Cars"
Mail.FromAddress= Request.Form("Email")
Mail.RemoteHost = "mrvnet.kundenserver.de"          
Mail.AddRecipient "London Heathrow Cars", "bookings@londonheathrowcars.com"
Mail.Subject    = "Booking Form"
strEmailText = strEmailText & "Day: " & Request.Form("day") & vbCrLf
strEmailText = strEmailText & "Month: " & Request.Form("month") & vbCrLf
strEmailText = strEmailText & "Year: " & Request.Form("year") & vbCrLf
strEmailText = strEmailText & "Time - Hours: " & Request.Form("hour") & vbCrLf
strEmailText = strEmailText & "Time - Minutes: " & Request.Form("minutes") & vbCrLf
strEmailText = strEmailText & "Single or Return: " & Request.Form("journey_type") & vbCrLf
strEmailText = strEmailText & "Special Requirements: " & Request.Form("special") & vbCrLf
strEmailText = strEmailText & "Pickup Address: " & Request.Form("padd") & vbCrLf
strEmailText = strEmailText & "Pick. Flight No: " & Request.Form("pflight") & vbCrLf
strEmailText = strEmailText & "Coming From: " & Request.Form("aircome") & vbCrLf
strEmailText = strEmailText & "Destination Address: " & Request.Form("dadd") & vbCrLf
strEmailText = strEmailText & "Dest. Flight No: " & Request.Form("dflight") & vbCrLf
strEmailText = strEmailText & "Title: " & Request.Form("title") & vbCrLf
strEmailText = strEmailText & "Name: " & Request.Form("myname") & vbCrLf
strEmailText = strEmailText & "Email: " & Request.Form("Email") & vbCrLf
strEmailText = strEmailText & "Phone: " & Request.Form("Phone") & vbCrLf
strEmailText = strEmailText & "No of Passengers: " & Request.Form("passengers") & vbCrLf
strEmailText = strEmailText & "Baby Seat: " & Request.Form("tick") & vbCrLf
strEmailText = strEmailText & "Luggage: " & Request.Form("luggage") & vbCrLf
strEmailText = strEmailText & "Car Type: " & Request.Form("car") & vbCrLf
strEmailText = strEmailText & "Payment Type: " & Request.Form("pay") & vbCrLf
strEmailText = strEmailText & "Contact me By: " & Request.Form("contact") & vbCrLf

Mail.BodyText = strEmailText
if Mail.SendMail then
  Response.Redirect "taxi-booking2.htm"
else
  Response.Write "Mail send failure. Error was " & Mail.Response
end if 
Set Mail = Nothing
%> 


</body>

</html>

and the html template
Code:
<html>
<head>
<title></title>

<meta name="description" content="">
<meta name="keywords" content="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body text="#333333">

<table border="0" width="560" id="table1" cellspacing="0" cellpadding="0">
	<tr>
		<td>
		<font color="#5A79B5" face="Arial">
		<img border="0" src="emaillogo.gif" width="560" height="113"></font></td>
	</tr>
</table>

		<table border="1" id="table4" cellspacing="0" cellpadding="0" bordercolor="#5A79B5" width="560" bordercolorlight="#5A79B5" bordercolordark="#5A79B5">
			<tr>
				<td align="center" valign="top">
				<table border="0" width="550" id="table5" cellpadding="2" cellspacing="1">
					<tr>
						<td colspan="2">
						<p align="left"><b>
						<font face="Arial" style="font-size: 16pt" color="#5A79B5">
						LONDON HEATHROW CARS</font></b></td>
					</tr>
					<tr>
						<td colspan="2">
						<font color="#000080" size="2">
						<span style="font-family: Arial; ">FAO Mr </span>
						<span style="font-family: Arial">this</span></font><p>
						<font color="#000080" size="2">
						<span style="font-family: Arial; ">Thank you for your 
						booking request. </span></font>
						<font face="Arial" size="2" color="#000080">blabla:</font><p>
						<font color="#000080" size="2" face="Arial"><b>UK Free phone:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0800 505 3231</b><br>
						<b>International:</b> <b>&nbsp;&nbsp;&nbsp;&nbsp; +44 (0) 208 814 1223</b><br>
						&nbsp;</font></td>
					</tr>
					<tr>
						<td colspan="2"><hr color="#5A79B5"></td>
					</tr>
					<tr>
						<td width="164"><b>
						<font face="Arial" size="2" color="#000080">Date:</font></b></td>
						<td width="375"><b>
						<font face="Arial" size="2" color="#000080">date goes 
						here</font></b></td>
					</tr>
					<tr>
						<td width="164">&nbsp;</td>
						<td width="375">&nbsp;</td>
					</tr>
					<tr>
						<td width="164"><b>
						<font size="2" face="Arial" color="#000080">From:</font></b></td>
						<td width="375">
						<font face="Arial" size="2" color="#000080">from</font></td>
					</tr>
					<tr>
						<td width="164"><b>
						<font face="Arial" size="2" color="#000080">ETA:</font></b></td>
						<td width="375">
						<font face="Arial" size="2" color="#000080">[b]put the pickup time here for example[/b]</font></td>
					</tr>
					<tr>
						<td width="164"><b>
						<font face="Arial" size="2" color="#000080">Flight:</font></b></td>
						<td width="375">
						<font face="Arial" size="2" color="#000080">flight 
						number</font></td>
					</tr>
					<tr>
						<td width="164"><b>
						<font face="Arial" size="2" color="#000080">To:</font></b></td>
						<td width="375">
						<font face="Arial" size="2" color="#000080">to here</font></td>
					</tr>
					<tr>
						<td width="164">&nbsp;</td>
						<td width="375">&nbsp;</td>
					</tr>
					<tr>
						<td width="164"><b>
						<font face="Arial" size="2" color="#000080">Vehicle 
						Type:</font></b></td>
						<td width="375">
						<font face="Arial" size="2" color="#000080">car</font></td>
					</tr>
					<tr>
						<td width="164"><b>
						<font face="Arial" size="2" color="#000080">Total fare:</font></b></td>
						<td width="375">
						&nbsp;</td>
					</tr>
					<tr>
						<td width="535" colspan="2"><hr color="#5A79B5"></td>
					</tr>
					<tr>
						<td width="535" colspan="2">
						<p>
						<font face="Arial" size="2" color="#000080">With kind regards</font></td>
					</tr>
					</table>
				</td>
			</tr>
		</table>
		
</body>

</html>

London Heathrow Cars
 
While I am not familiar with SMTPsvg.Mailer, with cdo, you can only have one format of an email in a single email. Your vbcrlf is used with text email, but your table will have to be in an html email. Therefore, you need to make the email format html and change your vbcrlf to <BR>. You will have to build all of the html cade for your table into the string that you are sending as the body...

strEmailText = strEmailText & "Day: " & Request.Form("day") & <BR> (and so on)

mytable = mytable & "<table border=""0"" width=""560"" id=""table1"" cellspacing=""0"" cellpadding=""0"">"<tr><td>" & Request.Form("day") & "</TD></TR>" (and so on)

Mail.BodyText = strEmailText & mytable
 
ok the reason that i used that email was because my host gave me this specific example to use..

How to use ASP Mail Component?


ASP Mail is an Active Server Component designed to send email from an Active Server Page. This component is installed on our servers.

Below is a sample Asp script that use Asp Mail component to send the feedback form information back to your desired email address.

You can edit the following script to your requirements.

Script : forminfo.asp
Code:
<% @LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head> 
<body> 
 

<% 

Set Mail = Server.CreateObject("SMTPsvg.Mailer")      'create an Asp mail component.
Mail.FromName   = "1&1 Test"
Mail.FromAddress= Request.Form("email")
Mail.RemoteHost = "mrvnet.kundenserver.de"          ' The mail server you have to use with Asp Mail
Mail.AddRecipient "Your Name", "support@1and1.co.uk"
Mail.Subject    = "Website - Info Request"
Mail.BodyText   = Request.Form("Info")
if Mail.SendMail then
  Response.Write "Your mail has already been sent..."
else
  Response.Write "Mail send failure. Error was " & Mail.Response
end if 
Set Mail = Nothing
%> 


</body>

</html>

now i tried altering this code as you said to make the email format html.. so i used the w3c example here..


Code:
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.HTMLBody = "<h1>This is a message.</h1>" 
myMail.Send
set myMail=nothing
%>

but throughout, it was tellin me that.. things such as FromName, and RemoteHost were not compatible with that email type.. so im kind of stuck.. i dont know a solution that keeps both parties happy.

London Heathrow Cars
 
If I wanted to email an HTML page that contains values submitted on a form, I would start by considering the Replace function.

Something like this:[tt]
strTemplate = "<html> ....[red]template stuff goes here[/red] .... </html>"

IF Request.Form("PickupTime") <> "" THEN
strTemp = Request.Form("PickupTime")
ELSE
strTemp = "Not specified"
END IF

Replace(strTemplate, "put the pickup time here for example", strTemp)

[/tt]
 
ok... im a little confused..

but i realise that i need to TRY and show some understanding if i want your continued help.. so here i go..

would my template look something like this??


Code:
<% @LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head> 
<body> 
 

<% 

Set Mail = Server.CreateObject("SMTPsvg.Mailer")
Mail.FromName   = "London Heathrow Cars"
Mail.FromAddress= Request.Form("Email")
Mail.RemoteHost = "mrvnet.kundenserver.de"          
Mail.AddRecipient "London Heathrow Cars", "bookings@londonheathrowcars.com"
Mail.Subject    = "Booking Form"



Mail.BodyText = "<table border="0" width="560" id="table1" cellspacing="0" cellpadding="0">
    <tr>
        <td>
        <font color="#5A79B5" face="Arial">
        <img border="0" src="emaillogo.gif" width="560" height="113"></font></td>
    </tr>
</table>

        <table border="1" id="table4" cellspacing="0" cellpadding="0" bordercolor="#5A79B5" width="560" bordercolorlight="#5A79B5" bordercolordark="#5A79B5">
            <tr>
                <td align="center" valign="top">
                <table border="0" width="550" id="table5" cellpadding="2" cellspacing="1">
                    <tr>
                        <td colspan="2">
                        <p align="left"><b>
                        <font face="Arial" style="font-size: 16pt" color="#5A79B5">
                        LONDON HEATHROW CARS</font></b></td>
                    </tr>
                    <tr>
                        <td colspan="2"><hr color="#5A79B5"></td>
                    </tr>
                    <tr>
                        <td width="164"><b>
                        <font face="Arial" size="2" color="#000080">Vehicle
                        Type:</font></b></td>
                        <td width="375">
                        <font face="Arial" size="2" color="#000080">[b]Vehicle Goes Here[/b]</font></td>
                    </tr>
                    </table>
                </td>
            </tr>
        </table>"


IF Request.Form("PickupTime") <> "" THEN
  strTemp = Request.Form("PickupTime")
ELSE
  strTemp = "Not specified"
END IF

Replace(strTemplate, "Vehicle Goes Here", strTemp)


if Mail.SendMail then
  Response.Redirect "taxi-booking2.htm"
else
  Response.Write "Mail send failure. Error was " & Mail.Response
end if 
Set Mail = Nothing
%> 


</body>

</html>

London Heathrow Cars
 
I try to do things the simple way, and would set up a page like:
Page 1
%>
<p>Subject:
&nbsp;<input type="text" name="Subject" size="73"></p>
Messsage:
<p><textarea rows="15" name="eMailMessage" cols="78"></textarea><br>
<%
You might want to add other input fields like "Where" and "When"

When the user submits the form:

PAGE 2
Data from the first page is retrieved using Request.Form("")
You may wish to concatenate some of the fields into a string.

Static data is generated through coding or from a table.

The message is then sent to you using:

Set oMSG = createobject("CDO.Message")
oMSG.To = veMailAddress
oMSG.From = vSender
oMSG.Subject = vSubject
oMSG.TextBody = veMailMessage
oMSG.Send()
set oMSG=nothing
 
I'm sorry I think I confused things.

I was assuming that you wanted to send HTML as the body of the email.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top