Reputation: 2376
A few weeks ago I implemented a mail function in my ASP Classic code but it generates a few strange markup / styling errors.
When a mail is send with the Mail function it sometimes outputs html tags literally while the syntax is correct.
See picture below for the literal html output:
As you can see in the picture below the font tag gets displayed literally while it is exactly the same as the other columns, that display correctly. The strange thing about it is that it sometimes displays the font wrong, then some random <TR>
tag, then 1 border that isn't displayed or a href
that gets messed up (on click of the href is generates some random %20 characters, while hovering over it it displays the href as it should).
Is this some kind of ASP classic mail function bug or..? It also seems that only one html tag gets displayed literally and never more than 1. Sometimes it also generates no literal tag at all (so it outputs correct).
The mail function is as follows:
Function SendMail(sBody,sEmail)
set mail=server.createobject("Persits.MailSender")
Mail.Host = "spamfilter.myWebsite.com" ' Required
Mail.Port = 587 ' Optional. Port is 25 by default
Mail.From = "[email protected]"
Mail.FromName = "My Name"
sEmail = Uploader.Form("EMail")
Mail.AddAddress sEmail
Mail.Subject = "Tickets: " & FormSubject
Mail.Body = sBody
Mail.IsHTML = True
Mail.send
End Function
This is how the mail body is generated:
sBody="<font face=""Verdana, Arial"" size=2 color=""black"">Geachte " & FormNaam & ",<br><br>"
sBody=sBody & "Recentelijk heeft u een ticket aangemaakt betreffende '<b>" & FormSubject & "</b>'.<br>"
sBody=sBody & "Wij zullen proberen uw ticket zo snel mogelijk te behandelen. Informatie over uw ticket kunt u hieronder terug vinden." & "<br><br>"
sBody=sBody & "<br>"
sBody=sBody & "<table>"
sBody=sBody & "<tr><th style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""#000080"">Verstuur datum</th><th style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""#000080"">Voor afdeling</th><th style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""#000080"">Soort ticket</th><th style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""#000080"">Onderwerp</th><th style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""#000080"">Ticket beschrijving</th></tr>"
sBody=sBody & "<tr bgcolor=""#BEC0F7"">"
sBody=sBody & "<td style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""black"">"
sBody=sBody & day(sToday)&"-" & month(sToday) & "-" & year(sToday)
sBody=sBody & "</td>"
sBody=sBody & "<td style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""black"">"
sBody=sBody & FormAutomatiseringClean
sBody=sBody & "</td>"
sBody=sBody & "<td style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""black"">"
sBody=sBody & FormProbleemClean
sBody=sBody & "</td>"
sBody=sBody & "<td style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""black"">"
sBody=sBody & FormOnderwerp
sBody=sBody & "</td>"
sBody=sBody & "<td style=""border: 1px solid black;""><font face=""Verdana, Arial"" size=2 color=""black"">"
sBody=sBody & FormBeschrijving
sBody=sBody & "</td></tr>"
sBody=sBody & "</table><br>"
Randomize
intLength = 100000
intRandom = CInt((Rnd * 10000)Mod intLength) + 1
'SELECT LAST ID OR ID OF THE SENDER/SUBJECT/SOMETHING UNIQUE
sBody=sBody & "De status van uw ingediende ticket kunt u bijhouden via de onderstaande knop:<br><br>"
sBody=sBody & "<table cellspacing=""0"" cellpadding=""0""><tr>"
sBody=sBody & "<td align=""center"" width=""200"" height=""35"" bgcolor=""#000091"" style=""-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;"">"
sBody=sBody & "<a href=""http://mywebsite/ticket.asp?type=ticket&ticketid="&TicketID&"&validatie="&FormRecode&""" style=""font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none; line-height:40px; width:100%; display:inline-block""><span style=""color: #FFFFFF"">Ticket Status</span></a><br><br>"
sBody=sBody & "</td></tr> </table><br>"
sBody=sBody & "Indien de knop het niet doet kunt u de volgende link volgen: http://mywebsite/ticket.asp?type=ticket&ticketid="&TicketID&"&validatie="&FormRecode&"<br><br>"
sBody=sBody & "With kind regards," & "<br><br>"
sBody=sBody & "My Company B.V." & "<br><br>"
sBody=sBody & "<font face=""Calibri, Arial"" style=""font-size:10pt;"" color=""black""><i>My company BV</i>" & "<br>"
sBody=sBody & "<font face=""Calibri, Arial"" style=""font-size:10pt;"" color=""gray"">GSome adress 22 | Some postal zip | Place" & "<br>"
sBody=sBody & "<font face=""Calibri, Arial"" style=""font-size:10pt;"" color=""gray"">Some text | Percel number 100" & "<br>"
sBody=sBody & "<font face=""Calibri, Arial"" style=""font-size:10pt;"" color=""black"">T: " & "<font face=""Verdana, Arial"" size=1 color=""gray"">0416-322792" & "<br>"
sBody=sBody & "<font face=""Calibri, Arial"" style=""font-size:10pt;"" color=""black"">F: " & "<font face=""Verdana, Arial"" size=1 color=""gray"">0416-322582" & "<br>"
sBody=sBody & "<font face=""Calibri, Arial"" style=""font-size:10pt;"" color=""black"">E: [email protected]" & "<br>"
sBody=sBody & "<font face=""Calibri, Arial"" style=""font-size:10pt;"" color=""black"">W: www.mysite.com" & "<br><br>"
err=SendMail(sBody,sEmail)
Upvotes: 1
Views: 923
Reputation: 16682
From experience using the Persits.MailSender
(As pointed out by @John this is a 3rd party component and not available by default, built-in alternative is CDO) I've always found that if the HTML is not structured correctly (i.e. Missing tag terminators) the results will not always be as expected.
In this specific case it is a HTML snippet not a true document as it is not properly defined;
<html> <head> </head> <body> </body> </html>
There is also no termination of <font>
tags using </font>
which I suspect is the cause of this problem.
I would however advise that you write HTML that passes validation in the future to avoid such problems.
Upvotes: 1