Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-03-03 13:49:30

lindabb
Member
Registered: 2023-02-17
Posts: 111

HTML formated email

Hello,
This function works, but the HTML formatted email sent as text

$mmessage = Txp::get(‘\Textpattern\Mail\Compose’) ->from(“user@xyz.com”, “NoReply”) ->to($sendto) ->subject( $subject) ->body( $body ); $mmessage->send();

Any idea how to keep the email HTML format as sent ?
No issue with my email to read any HTML formatted email.
Thank you

Offline

#2 2023-03-03 14:01:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,293
Website GitHub

Re: HTML formated email

How did you define your HTML email component in $body? Did you add all the multipart mime headers correctly?

You might also try:

$mmessage = Txp::get('\Textpattern\Mail\Compose')->getDefaultAdapter();

And then add the body and subject etc afterwards to that object. That will ensure that it uses the Prefs setting to deliver mail using the defined mechanism. See how com_connect does it for clues.

If sending directly, you may need to flag the object as ->isHTML() too, but in theory the default adapter will do that for you when you add your $body, as long as it’s formatted as multipart mime.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2023-03-03 14:15:44

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: HTML formated email

Thank you Bloke,
No, I didn’t, just passed email as HTML format, like this

<B>Hello world</B><hr>
<P><a href=“url”>Click here to download 2023 community springs events</a></p>

Is there option to add multipart mime headers?

Thank you

Last edited by lindabb (2023-03-03 14:18:37)

Offline

#4 2023-03-03 14:25:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,293
Website GitHub

Re: HTML formated email

lindabb wrote #334889:

Is there option to add multipart mime headers?

If you’re using com_connect, it’s easy. Otherwise, nothing built into core as far as I recall. I’d have to refresh my memory in the code.

If you’re sending HTML dircetly via PHPMailer, you can call that isHTML() method (I think that’s what it’s called). That instructs it that your content is formatted as such, and you should be able to send HTML as you’ve defined it.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2023-03-03 16:13:42

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: HTML formated email

Thank you Bloke
I’m able to use PHPmailer and send HTML format email. wasn’t hard to implement it.
com_connect good for ready to use contact, my problem to send custom email to community users.
plus send download emails by request.
I created new plugin that grabs email template (I have 21 templates) and sends email just passing 2 inputs (email, template_name)
example:
new registered user, forgotten password , change password, latest news, community yard sale, events so on.

Thanks again

Offline

Board footer

Powered by FluxBB