Uniform email form says success, but no mail is sent

I’m in the process of finalising my latest Kirby site (having not used it for a while). I’m using Uniform to create a contact form and it all works fine. It even displays the correct messages when submitting the form to send the mail, both errors and success.

The issue I have is that even though it says “Success!”, no mail ever arrives - yes, I have checked in the Spam folder!

Here is my form:

<form action="<?php echo $page->url() ?>#contact-notice" method="POST" id="contactform">
	<fieldset>
		<legend>Get in touch with Us</legend>
		<div class="form-row">
			<label for="name">Name <span class="req">*</span></label>
			<input<?php if ($contactform->error('name')): ?> class="error"<?php endif; ?> name="name" id="name" type="text" placeholder="Your name" value="<?php echo $contactform->old('name') ?>">
		</div>
		<div class="form-row">									
			<label for="email">E-mail <span class="req">*</span></label>
			<input<?php if ($contactform->error('email')): ?> class="error"<?php endif; ?> name="email" id="email" type="email" placeholder="Your e-mail" value="<?php echo $contactform->old('email') ?>">
			<?php echo honeypot_field('url','contact-website-hp') ?>
		</div>
		<div class="form-row">									
			<label for="phone">Phone</label>
			<input name="phone" id="phone" type="text" placeholder="Your phone" value="<?php if ($contactform->old('phone')): echo $contactform->old('phone'); endif; ?>">
		</div>
		<div class="form-row">
			<label for="message" class="message-label">Message <span class="req">*</span></label>
			<textarea<?php if ($contactform->error('message')): ?> class="error"<?php endif; ?> name="message" id="message" placeholder="Your message..."><?php echo $contactform->old('message') ?></textarea>
		</div>
		<div class="form-row asf">
			<?php echo csrf_field() ?>
			<input type="hidden" name="submittedfrom" value="<?= $page->url() ?>">
			<label for="as-result">Anti-spam question: What is <?php echo uniform_captcha() ?>? <span class="req">*</span></label>
			<?php echo captcha_field('as-result', 'field-asf'); ?>
		</div>
		<a id="contact-notice"></a>
		<div class="form-row button-row">
			<input type="hidden" name="formid" value="contact">
			<input type="submit" class="button primary" value="Send Message">
		</div>
	</fieldset>
</form>
	<?php if ($contactform->success()): ?>
	<div class="uniform-success">
		Thank you for your message. We will get in touch soon!
	</div>
	<?php else: ?>
		<?php snippet('uniform/errors', ['form' => $contactform]) ?>
	<?php endif; ?>

And here is my controller:

return function ($kirby)
{
    $contactform = new Form([
        'name' => [
			'rules' => ['required'],
            'message' => 'Please enter your name',
		],
		'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Please enter a valid email address',
        ],
        'phone' => [],
        'message' => [
            'rules' => ['required'],
            'message' => 'Please enter a message',
        ],
		'submittedfrom' => [],
		'as-result' => [
			'rules' => ['required', 'num'],
			'message' => 'Please fill in the calculation field',
		],
    ],'contact-form');
	
    if ($kirby->request()->is('POST')) {
		$contactform
			->honeypotGuard(['field' => 'url'])
			->calcGuard(['field' => 'as-result'])
			->emailAction([
			'to' => 'name@address.co.uk',
			'from' => 'website@address.co.uk',
			'subject' => 'Contact form submission from {{name}} via address.co.uk'
		])->done();
    }
    return compact('contactform');
};

I’m using Kirby 5.0.3 and Uniform 5.7.0, running on PHP 8.4

I feel like I’m going around in circles on this and could really do with some guidance on how to error check it all. There is nothing in the error log for the host.

Are you testing this on a localserver (MAMP, Herd, Valet, etc)?

If so you would need to use something like Mailhog to intecept the emails. Unform may well sent the email as far as it is concerned but its probably hasnt actually left your computer.

See here on how to get mailghog going, although you might have to adapt it slightly to work with uniforms config rather then the Kirby built in emailing.

Do you get the same result when you send the form from a public webserver?

Hi @jimbobrjames - Thanks for pointing me in that direction. I had a look and I’m afraid I couldn’t make head nor tail of how to setup and use MailHog.

I can confirm that the issue is the same in both local (MAMP) and remote/live server environments.

Is it possible that the mail function that Kirby uses by default could be disabled on the server?

I honestly don’t know - I’m clutching at straws a little here!

Trying to send real email from your dev environment often does not work and should be avoided, as your senders email might get spam blocked.

So setting up MailHog or MailPit or a similar tool locally is indicated. Where exactly did you get lost with the setup?

Regarding your live environment, while sendmail() sometimes works, it is better to set up an SMTP provider, and make sure that your sending domain is properly configured to prevent being marked as spam.

Hey @texnixe - Yes, I wasn’t really doing full testing the dev environment because I know it doesn’t really work; I mentioned it again because @jimbobrjames said about using MailHog with the local server for testing. I couldn’t really workout where to put the files or how to set it up (I’m really a designer with some development knowledge so have areas that I draw a blank in)

I assumed that if sendmail() didn’t work on the server that it would error, but I guess it could just appear to work, but not actually do anything. Would that make sense?

Either way, I think I need to move the site to it’s final home and try to work it out there as the solution is looking more likely to be server-specific!