This topic is locked

email sent from html template arrive inbox as plain txt

10/8/2020 10:42:15 AM
ASPRunner.NET General questions
A
admin author

Hi experts,
I am testing how to use custom templates for emails sent from asprunner.net 10.4
My test template have this content
Nyheder fra CarMagic.dk - glæd dig

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.o=

rg/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns=3D"http://www.w3.org/1999/xhtml">;

<head>

<meta charset="utf-8">

<title>Untitled Page</title>

<meta name="generator" content="WYSIWYG Web Builder 16 - http://www.wysiwygwebbuilder.com">;

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

<div id="wb_Text1">

<span style="color:#000000;"><strong>Velkommen til hos Carmagic.dk</strong></span></div>

</body>

</html>
The email arrives but as plain text - anybody knowing what i am doing wrong or missing?
Thank you in advance
Michael Fiil (Denmark)

Pete K 10/9/2020

Are you using the runner_mail function to send the mail? If so, make sure you are using the htmlbody parameter rather than body.

A
admin author 10/9/2020

Hi Pete, thank you for participating,
Continuing testing, i have tryed both:
CommonFunctions.sendEmailTemplate - sends plain text

MVCFunctions.runner_mail - works - but heavy programming if sending newsletters with pictures ect.
Today i found out that runner_mail do the job but sendEmailTemlate sends only plain text.
Now i have this custom file named newstemplate.html
<html>

<head>

<title>Help Kids Code Project | How to Code an HTML Email</title>

</head>

<style type="text/css">

@media only screen and (max-width: 480px) {

/ mobile-specific CSS styles go here /

table[class=email], table[class=email-content] { clear: both; width: 320px !important; }}

</style>

<body>

<table width="99%" border="0" cellpadding="0" cellspacing="0">

<tr><td align="center" valign="top" bgcolor="#efefef">

Dear %cname%</td></tr>

<tr><td align="center" valign="top" bgcolor="#efefef">

This is testing</td></tr>

</table>

</body>

</html>
using this code in button (server event):

XVar dataarr = XVar.Array();

string email;

string strSQLExists = "select from customers where id=" + parameters["cusid"].ToString();

XVar rsExists = CommonFunctions.db_query(strSQLExists, null);

XVar data = CommonFunctions.db_fetch_array(rsExists);

dataarr.InitAndSetArrayItem(data["name"], "cname");

dataarr.InitAndSetArrayItem(data["created"], "membsince");

email = data["email"];

CommonFunctions.sendEmailTemplate(email, "newstemplate.html", dataarr);
sends plain text to reciever inbox!!
Using this code in button (server event):

XVar dataarr = XVar.Array();

string email;

string strSQLExists = "select
from customers where id=" + parameters["cusid"].ToString();

XVar rsExists = CommonFunctions.db_query(strSQLExists, null);

XVar data = CommonFunctions.db_fetch_array(rsExists);

dataarr.InitAndSetArrayItem(data["name"], "cname");

dataarr.InitAndSetArrayItem(data["created"], "membsince");

email = data["email"];

string from = "crm@carmagic.dk";

string msg = "<html>";

msg = msg + "<head>";

msg = msg + "<title>Help Kids Code Project | How to Code an HTML Email</title>";

msg = msg + "</head>";

msg = msg + "<style type='text/css'>";

msg = msg + "@media only screen and (max-width: 480px) {";

msg = msg + " / mobile-specific CSS styles go here /";

msg = msg + "table[class=email], table[class=email-content] { clear: both; width: 320px !important; }";

msg = msg + "}";

msg = msg + "</style>";

msg = msg + "<body>";

msg = msg + "<table width='99%' border='0' cellpadding='0' cellspacing='0'>";

msg = msg + "<tr><td align='center' valign='top' bgcolor='#efefef'>";

msg = msg + "Dear " + data["name"].ToString() + "</td></tr>";

msg = msg + "<tr><td align='center' valign='top' bgcolor='#efefef'>";

msg = msg + "This is testing</td></tr>";

msg = msg + "</table>";

msg = msg + "</body>";

msg = msg + "</html>";

string subject = "This is testing MVCFunctions.runner_mail with html";

XVar mresult;

mresult = MVCFunctions.runner_mail(new XVar("to", email, "subject", subject, "htmlbody", msg, "from", from));
sends an email with html content to inbox :-)
Am i missing something in my code using sendEmailTemplate ??
Thank you in advance
Kind regards
Michael Fiil (Denmark)