Sending external form as html instead of plaintext (setAdditionalHeaders for adding header item to external form)

Permalink
I found setAdditinoalHeaders in the API, but I'm unsure how to pass it the data it needs.

I need to add a new header type so I can include HTML in the email that gets delivered:

The header I would like to add is:
"Content-Type: text/html; charset=ISO-8859-1\r\n";

The mail API is here:

http://documentation.concrete5.org/api/class-Concrete.Core.Mail.Ser...

If I pass new headers via:
setAdditionalHeaders( array $headers, string $val,)


how do I pass the above header this way?

ob7dev
 
ob7dev replied on at Permalink Reply
ob7dev
I was able to pass the header I wanted like so:

$headers = [
"Content-Type" => "text/html; charset=ISO-8859-1",
];
$mail->setAdditionalHeaders($headers);


Which works, my only problem is, now I have Content-Type set twice in the email coming in. It still renders the HTML, but the message header has two content types, not sure if thats ok or not...
In the incoming email:
Content-Type: text/html;
 charset="ISO-8859-1"
MIME-Version: 1.0
Content-Type: text/plain;
 charset="UTF-8"


Is it ok to have double content types like this? It does seem load the html. But is there a better way?
ob7dev replied on at Permalink Best Answer Reply
ob7dev
Scratch my above answer, that is for adding additional headers not normally present in an email sent from website.

The built in mailer service already contains the functionality to send email as HTML instead of plainText, and its very simple:

Instead of using
$mail->setBody($body);

when sending the mail, use the setBodyHTML method instead:
$mail->setBodyHTML($body);