Elxis CMS Forum
Support => Technical support => Topic started by: michalis1984 on May 02, 2020, 11:58:50
-
Hello,
Can I use elxis sendmail function to send HTML emails? And if yes how?
-
With newsletter module it can!
https://www.elxis.net/edc/communication/61.html
-
I was looking for the class but i find it
$elxis->sendmail($subject, $body, '', null, 'html', $to, null, null, $from, 3, false, $replyto);
-
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.
-
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?
-
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';
-
Full documentation in elxis docs: https://www.elxis.net/docs/developers/tutorials/sending-emails.html
-
Thank you again datahell!
Too bad of me I didn't notice the post at the elxis docs. It's there since 2012 :D