CF7 Mail Content-Type - send email using PHP

How to send plain text emails with ChronoForms.

Overview

The problem is that ChronoForms sends all emails as HTML by default, with no built-in option to switch to plain text format.
To send plain text emails, you must use custom PHP code within your form to create and send the email, explicitly setting the email format to plain text.

Answered
ChronoForms v7
as asitun 16 Jan, 2024
Hello,
I'm using Chronoforms 7 with Joomla 5.0.2.

I can't find any switch for sending mails as content-type text/plain. All mails sended as html.

I tried admin mail, user mail and advanced form mail, with any option to switch.

It's important for me to send mails as text/plain.

Any solution for this goal?

Thank's.
Max_admin Max_admin 19 Jan, 2024
Answer
a switch to send email in text mode has not been added because almost everyone uses html emails, if this is a must for you then you can send an email using PHP code:

// Assuming you are inside a Joomla component or module

// Load Joomla's mail library
jimport('joomla.mail.mail');

// Recipient details
$recipient = 'user@domain.com';

// Subject of the email
$subject = 'Your Email Subject';

// Message body in plain text
$body = 'Hello,

This is a plain text email message.

Regards,
Your Name';

// Instantiate the Joomla mail object
$mail = JFactory::getMailer();

// Set sender
$mail->setSender(array("from@domain.com", "from name"));

// Add a recipient
$mail->addRecipient($recipient);

// Set subject
$mail->setSubject($subject);

// Set the body of the email
$mail->setBody($body);

// Set the email format to plain text
$mail->IsHTML(false);

// Send the email
$sent = $mail->Send();

if ($sent !== true) {
    // The email failed to send
    JFactory::getApplication()->enqueueMessage('Error sending email: ' . $sent, 'error');
} else {
    // The email was sent successfully
    JFactory::getApplication()->enqueueMessage('Email sent successfully', 'message');
}



change the values as you need, you can get the value of any form field using:
$this->data("field_name")
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.