I have smtp configured in a server, in config, like:
'email' => [
'transport' => [
'type' => 'smtp',
'host' => 'xxxxx.yyyyyyy.zz',
'port' => 465,
'security' => true,
'auth' => true,
'username' => 'bot@site.com',
'password' => '1234567890',
]
Then, in a controller, I am using this code to send emails:
if ($kirby->request()->is('POST')) {
$name = get('your-name');
$email = get('your-email');
$message = get('your-message');
// Send email
if (site()->contactemail()->isNotEmpty()) {
try {
kirby()->email([
'from' => strval($email),
'to' => strval(site()->contactemail()),
'subject' => 'Contact from ' . $name,
'template' => 'contact',
'data' => [
'name' => $name,
'email' => $email,
'message' => $message
]
]);
$submitted = true;
} catch (Exception $e) {
// etc
}
}
}
bot@site.com and site()->contactemail() do NOT belong to the same server/company/hosting plan… the second is a standalone gmail account.
As you see I use $email as sender in ‘from’ field, so the sender email is always changing, which is contributing to emails being labeled as spam, because the client cannot whitelist the sender.
If, instead, I use bot@… as sender in ‘from’ field the client CAN whitelist that account, but then all emails are grouped in a single thread, and client does not like that (me neither).
Is there anything PHP I can add to the email code that allows me to ensure emails will not be sent to spam in gmail ? Any combination of fields that would allow the email to be identified as coming from bot@… while keeping the $email visible and remaining in separate threads, etc ?
As I understand I could do something like:
'from' => ['bot@site.com', $email]
…which would solve half of the problem (shown name) but not the other half (thread grouping), right?
Google suggests to Send each message with a unique reference header value that doesn’t match a previous message
. How to achieve this with $kirby->email()
?
I’ve cheked in gmail, and it does not seem to be able to whitelist by server, btw, at least not for regular accounts.
Thank you!