Thanks @mzur
So in the end made a new email service here: site/plugins/email-services.php
It’s a just copy of the default mail driver form. Here’s the mail driver and contact form controller in case anyone is interested
Email Driver:
/**
* Extend default mail driver
*/
email::$services['extended'] = function($email)
{
$headers = array(
'From: ' . $email->from,
'Reply-To: ' . $email->replyTo,
'Return-Path: ' . $email->replyTo,
'Message-ID: <' . time() . '-' . $email->from . '>',
'X-Mailer: PHP v' . phpversion(),
'Content-Type: text/plain; charset=utf-8',
'Content-Transfer-Encoding: 8bit',
);
$additional_parameters = $email->options['additional_parameters']; // the service-options parameter from the controller seems to be called options in the email driver
ini_set('sendmail_from', $email->from);
$send = mail($email->to, str::utf8($email->subject), str::utf8($email->body), implode(PHP_EOL, $headers), $additional_parameters);
ini_restore('sendmail_from');
if(!$send) {
throw new Error('The email could not be sent');
}
};
Controller:
use Uniform\Form;
return function ($site, $pages, $page) {
$form = new Form([
'name' => [
'rules' => ['required'],
'message' => 'Please enter a name',
],
'email' => [
'rules' => ['required', 'email'],
'message' => 'Please enter a valid email address',
],
'subject' => [
'rules' => ['required'],
'message' => 'Please enter a subject line',
],
'message' => [
'rules' => ['required'],
'message' => 'Please enter a message',
],
]);
if (r::is('POST')) {
$form->emailAction([
'to' => $page->email(),
'from' => 'client@clientemail.com',
'service' => 'extended',
'service-options' => ['additional_parameters' => '-f noreply@clientemail.com'],
]);
}
return compact('form');
};
Unfortunately all emails are still being picked up by gmail’s spam filter. I’ve contacted the hosting provider. But anyone have any ideas?