Uniform contact form works on localhost but not on server

Hello, I put together a uniform contact form on a one pager and it sends mails on localhost & logs the messages, but on the server I get a 302 in the network tab.

Here’s my snippet

 <form action="<?php echo $page->url() ?>/" method="POST">

      <fieldset class="margin-bottom-md">
         <div class="grid gap-md">
            <div class="col-6@md form-validate__input-wrapper js-form-validate__input-wrapper">
               <label class="form-label margin-bottom-xxs" for="name">Name</label>
               <input class="form-control <?php if ($form->error('name')): ?>error<?php endif; ?> width-100%" name="name" type="name" value="<?php echo $form->old('name') ?>" id="name" minlength="3" placeholder="full name">

               <?php if ($form->error('name')): ?>
                     <div class="bg-error padding-x-xs padding-y-xxs margin-top-xxs">
                     <span class="tooltip">Must be a name atleast 3 characters</span>
                  </div>
               <?php endif ?>


               <div role="alert" class="form-validate__error-msg bg-error padding-x-xs padding-y-xxs text-xs color-contrast-higher margin-top-xxs">
                  <span class="tooltip">Must be a name atleast 3 characters</span>
                  <?php echo implode($form->error('name')) ?>
               </div>
            </div>

            <div class="col-6@md form-validate__input-wrapper js-form-validate__input-wrapper">
               <label class="form-label margin-bottom-xxs" for="email">email</label>
                <input class="form-control <?php if ($form->error('email')): ?>error<?php endif; ?> width-100%" name="email" type="email" id="email" placeholder="email" value="<?php echo $form->old('email') ?>" required>
               
                  <?php if ($form->error('email')): ?>
                     <div class="bg-error padding-x-xs padding-y-xxs margin-top-xxs">
                     <span class="tooltip">Provide a valid email address.</span>
                  </div>
                  <?php endif ?>

               <div role="alert" class="form-validate__error-msg bg-error padding-x-xs padding-y-xxs text-xs color-contrast-higher margin-top-xxs">
                  <span class="tooltip">Provide a valid email address.</span>  
                  <?php echo implode($form->error('email')) ?>
               </div>
            </div>

            <div class="form-validate__input-wrapper js-form-validate__input-wrapper">
               <label class="form-label margin-bottom-xxs" for="textarea">Message</label>

               <textarea class="form-control <?php if ($form->error('message')): ?>error<?php endif; ?> width-100%" name="message" placeholder="message" id="textarea" minlength="10" required><?php echo $form->old('message') ?></textarea>
                  <?php if ($form->error('message')): ?>
                     <div class="bg-error padding-x-xs padding-y-xxs margin-top-xxs">
                     <span class="tooltip">Must be at least 10 characters.</span>
                  </div>
                  <?php endif ?>
                  <div role="alert" class="form-validate__error-msg bg-error padding-x-xs padding-y-xxs text-xs color-contrast-higher margin-top-xxs">
                  <span class="tooltip">
              

               </div>
            </div>

            <?php echo csrf_field(); ?>
            <?php echo honeypot_field(); ?>
         </div>
         </fieldset>

            <div class="text-center padding-top-sm">
               <input class="btn btn--primary" type="submit" value="Submit" formnovalidate>
            </div>
</form>

   <?php $session = kirby()->session(); ?>
   <?php if (kirby()->session()->get('success')): ?>

   <div class="form-control bg-success margin-top-md"> 
   <?= $session->get('success') ?>
   <?php $session->remove('success') ?>

   </div>
   <?php endif; ?>

and my controller

<?php

use Uniform\Form;

return function ($kirby) {
   $form = new Form([

        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Email is required',
        ],
        'name' => [
            'rules' => ['required', 'min' => 3]        
        ],
        'message' => [
            'rules' => ['required', 'min' => 10],
            'message' => 'Please enter a message',
        ],
   ]);

   if ($kirby->request()->is('POST')) {
    $form->emailAction([
        'to' => 'info@domain.com',
        'from' => 'no-reply@domain.com',
        'subject' => 'New mail from {{email}}',
      ])->logAction([
        'file' => kirby()->roots()->site().'/messages.log',
        
      ]);

    if ($form->success()) {
      $kirby->session()->set([ 'success' => 'Your message has been sent, thank you. We will get back to you soon!' ]);
      go('/#contact');
    }

   }

   return compact('form');
};

Network:

Übersicht
URL: https://domain.com/
URL: https://domain.com/
Status: 200
Quelle: Netzwerk
Adresse: some ip adress

Anfrage
GET /
Referer: https://domain.com/
Origin: https://domain.com
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15

Umleitungsantwort
302
Date: Tue, 15 Mar 2022 14:41:15 GMT
Location: https://domain.com/

Anfrage
:method: POST
:scheme: https
:authority: domain.com
:path: /
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: https://domain.com
Cookie: kirby_session=723652d321588fda2cf309f07aae1f017b2623c3%2B1647360161.9a83d0f5d68c4b18c158.0ae764940159cdc759ac73535422090c43b6ef14b889f4943ae844563f04ed3e
Accept-Encoding: gzip, deflate, br
Host: domain.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15
Accept-Language: de-at
Referer: https://domain.com/
Connection: keep-alive

Antwort
:status: 200
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Date: Tue, 15 Mar 2022 14:41:15 GMT
Accept-Ranges: bytes
Content-Encoding: gzip
Content-Length: 11455
Server: nginx
x-cache-status: MISS

Anfragedaten
MIME-Typ
Anfragedaten: ->
name=name&email=office@test.com&message=Test+15%3A41+website&csrf_token=d45876f70605170eeea35ec6f06f477fd0599021f4cbe16aa25ef45c0aef5c7a&website=

Any help would be appreciated @mzur (:

Thank you
Yulia

The 302 is normal, as Uniform uses the “POST, Redirect, GET” pattern. When the form is submitted, you always get a redirect response. The problem here is supposedly that the form actions are not performed. Do you get any error messages from the form? Please try to enable Kirby’s debug mode and see if any errors are reported then.

Thanks for your reply.

I enabled the debug mode, and sent a message over the form, but no error ):

Could it be some server settings?

Probably, as it works locally but not on the server. There must be an error message somewhere (unless you run out of memory but I don’t think so). Please add this snippet to your template. It prints all error messages if there are any:

<?php if ($form->success()): ?>
    Thank you for your message. We will get back to you soon!
<?php else: ?>
    <?php snippet('uniform/errors', ['form' => $form]) ?>
<?php endif; ?>
1 Like

Thank you so much!!! Now I was able to figure it out.

It logged:
There was an error sending the form: Could not instantiate mail function.

config.php

return [
    'debug' => false,
    'email' => [
        'transport' => [
        'type' => 'smtp',
        'host' => 'sslout.df.eu',
        'port' => 465,
        'security' => true,
        'auth' => true,
        'username' => 'no-reply@domain.com',
        'password' => '************',
        ]
    ]
];