Elxis CMS Forum

Support => Technical support => Topic started by: michalis1984 on May 02, 2020, 11:58:50

Title: Can elxis send html emails?
Post by: michalis1984 on May 02, 2020, 11:58:50
Hello,

Can I use elxis sendmail function to send HTML emails? And if yes how?
Title: Re: Can elxis send html emails?
Post by: Blacksoll on May 04, 2020, 13:16:36
With newsletter module it can!
https://www.elxis.net/edc/communication/61.html
Title: Re: Can elxis send html emails?
Post by: michalis1984 on May 04, 2020, 14:40:45
I was looking for the class but i find it

Code: [Select]
$elxis->sendmail($subject, $body, '', null, 'html', $to, null, null, $from, 3, false, $replyto);
Title: Re: Can elxis send html emails?
Post by: datahell on May 04, 2020, 22:44:54
Elxis can send any type of email you want. Plain text, html, both plain/html, with attachments, mass mail, and more.

You found the correct function, I type it once more for clarification:
sendmail($subject, $body, $alt_body='', $attachment=null, $type='plain', $to=null, $cc=null, $bcc=null, $from=null, $priority=3, $debug=false, $replyto=null)

So, to send html email:
$elxis->sendmail('My subject', $html_text, $optional_plain_text, null, 'html', 'test@example.com');

Tip: The additional plain text message is used when the email client doesn't want or doesn't support html emails. So in this case he will see the plain text message instead. If you ommit it he will see the html one without the html format which most probably will look ugly. So it is a good practice to include an alternative plain text message when sending html emails.

Ask you have any questions regarding the function parameters.
Title: Re: Can elxis send html emails?
Post by: michalis1984 on May 05, 2020, 02:46:37
Thank you datahell! The tip is very useful.

I want to learn more about the $attachment parameter.

What if I want to attach an image or a pdf file at the email (which is already uploaded)? How do I use that parameter? Full URL or any special elxis internal link?
Title: Re: Can elxis send html emails?
Post by: datahell on May 05, 2020, 08:45:14
To attach a file you use the ABSOLUTE PATH to the file, not a url. You can use the ELXIS_PATH constant which is the absolute path to elxis installation folder without trailing slash.

$file = ELXIS_PATH.'/something/test.pdf';
Title: Re: Can elxis send html emails?
Post by: datahell on May 05, 2020, 08:48:38
Full documentation in elxis docs: https://www.elxis.net/docs/developers/tutorials/sending-emails.html
Title: Re: Can elxis send html emails?
Post by: michalis1984 on May 05, 2020, 18:08:38
Thank you again datahell!

Too bad of me I didn't notice the post at the elxis docs. It's there since 2012 :D