I am using the SendGrid API to send html emails from my site using the following function:
function sendFormData2() {
const subject = `Test HTML Email`;
const body = "<p>Hello<span style='color: #ff0000;'><strong>World</strong></span></p>";
sendEmail2(subject, body)
.then(response => console.log(response));
}
The email sends successfully but reads as follows:
![](https://static.wixstatic.com/media/a27d24_a7dd287d0e0d43b58e874bef00e62228~mv2.png/v1/fill/w_200,h_30,al_c,q_85,enc_auto/a27d24_a7dd287d0e0d43b58e874bef00e62228~mv2.png)
This is due to the semicolon in the code after #ff0000. In this example I could remove the semicolon but there will be examples where a semicolon is required to separate multiple html styling parameters. When I remove the semicolon, the body of the email looks as follows (the way I want it to):
![](https://static.wixstatic.com/media/a27d24_cb1089b686ba47ad8eea53bf6f13d17e~mv2.png/v1/fill/w_95,h_26,al_c,q_85,enc_auto/a27d24_cb1089b686ba47ad8eea53bf6f13d17e~mv2.png)
I thought I could use semicolons freely in a string but it seems to be terminating the line of code. Can anyone advise?
Hi @Iain Downer, were you able to find some solution for this? I'm stuck at the same issue.
Try unicodes:
here are some unicodes for ';'
U+0003B
;
;
;
\003B
If your mail is still getting chopped off after semicolon try removing the semicolon at the end of the unicodes:
U+0003B
;
;
&semi
\003B
If it still doesn't work, Ion know no more. I'm then guessing its from they side.
Try backticks and make sure SendGrid's body type is set to html in the api call
const body = `<p>Hello<span style='color: #ff0000;'><strong>World</strong></span></p>`;
Hi, Iain Downer. This is WAG; does it work if you replace the assignment of the body constant with the following:
const body = '<p>Hello<span style="color: #ff0000;"><strong>World</strong></span></p>';
? (I "inverted" your use of apostrophes and double quotes.)
If that doesn't work, I'm wondering if JavaScript is considering that the end of the statement and, as a result, the internal semicolon needs to be escaped (i.e., preceded by a backslash) as follows:
const body = '<p>Hello<span style="color: #ff0000\;"><strong>World</strong></span></p>';
or:
const body = "<p>Hello<span style='color: #ff0000\;'><strong>World</strong></span></p>";
?