How to send an E-Mail via TLS

I’m building a Kirby-website with an e-mail contactform like this one.
The client wants the mail to be secure, not PGP secure (too complicated for the users), but at least TLS secure. Can I make that happen with the above contact form example? Is it maybe already happening?
Or do I need PHPMailer or something else on the server for this?
The site will be hosted at 1und1 and at least the contact form site will only be reachable via https.
I would be really happy if somebody could point me in the right direction. I don’t have a clue right now as to how this all works.

Hi there!

You can send an email just by using Kirbys builtin feature
As you already mentioned this is not providing too much options regarding security levels.

PHPMailer is one option that supports TLS, but you would need a SMTP server to send emails.
Since you already got a hoster that is probably providing SMTP services, you should be good to go with that.

There is no special requirement regarding Kirby when using PHPMailer.
What needs to be done is setting up a php page to handle mail.

Like this:

// include PHPMailer
require '<path>/<to>/PHPMailerAutoload.php';

// set some options
$mail->Host = '';
$mail->Username = 'user';
$mail->Password = 'password';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->ClearAllRecipients(); //better to clear first, if in a loop of batch sending emails
$mail->CharSet = 'utf-8'; 
$mail->From = "<email>"; // from address
$mail->FromName = "<name>"; // from name

$mail->WordWrap = 75;
$mail->Subject = 'Subject';
$mail->Body = '<content>'; // can be headers, html, css, etc.
$mail->AltBody = 'add some text for non-html mail';
$mail->isHTML(true); // Set email format to HTML

if(!$mail->send()) {
    echo ' Message could not be sent.' . PHP_EOL;
    echo ' Mailer Error: ' . $mail->ErrorInfo . PHP_EOL;
} else {
    echo "Mail sent.";

…as far, as I remember. :smile:

You may also have a look on github for further documentation of PHPMailer.