Uniform Mail SMTP / Warning

I am trying to set up a form using Uniform (Kirby 2 Branch) and PHPMailer using the tutorial Contact form with phpmailer + Uniform.

Emails are being sent, but Gmail flags them as dangerous. Due to this I added service-options to use the SMTP-server. But seems like this is not working (because it has no effect on Gmail flagging it as potentially dangerous.

I need to send the form using basic text (no template needed) without it being flagged as dangerous.
I would be grateful for any help! If it is easier without PHPMailer, any help in that direction is very welcome as well.

Below is my controller code. The rest is the same as in the linked tutorial.

<?php

use Uniform\Form;

return function ($site, $pages, $page) {

    $form = new Form([
        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Die Email-Adresse scheint ungültig zu sein',
        ],
        'name' => [],
        'message' => [
            'rules' => ['required'],
            'message' => 'Bitte eine Nachricht eingeben',
        ],
        'receive_copy' => [],
    ]);

    if (r::is('POST')) {
        $to = 'MY_NAME@gmail.com';

        $form->emailAction([
            'to' => $to,
            'from' => $to,
            'subject' => 'Kontaktanfrage von {name}',
            'receive-copy' => false,
            'service' => 'phpmailer',
            'service-options' => [
                'host'     => 'smtp.gmail.com',
                'port'     => 587,
                'security' => 'tls',
                'user'     => 'MY_NAME@gmail.com',
                'password' => 'MY_PASSWORD;',
            ],
        ]);
    }

    return compact('form');
};

@mzur

I suspect it is because both your to and from addresses are ‘MY_NAME@gmail.com’ - but gmail can work out it didn’t send it! You may have more luck if you set the from as something@originatingyourdomain.com - although testing that locally may still product differing results.

I’d really recommend using an external mailing service rather than using phpmailer, and you’ll get the benefit of decent logging. Something like https://www.mailgun.com/ is free for the level of use of an average contact form, and is easy to integrate with uniform.