I think you want something like this
https://github.com/DominicWatts/ContactResponse
Much of the hard work is done by the plugin
https://github.com/DominicWatts/ContactResponse/blob/48e9cb23f72990551d5c2dbb51605871024e53b2/Plugin/Frontend/Magento/Contact/Model/Mail.php#L72-L116
public function afterSend(
\Magento\Contact\Model\Mail $subject,
$result,
$variables,
$replyTo
) {
if (!$this->helper->getConfirmation()) {
return;
}
/** @see \Magento\Contact\Controller\Index\Post::validatedParams() */
$replyToName = !empty($replyTo['data']['name']) ? $replyTo['data']['name'] : null;
$replyToEmail = !empty($replyTo['data']['email']) ? $replyTo['data']['email'] : null;
// $this->contactsConfig->emailSender(); string
// $this->contactsConfig->emailRecipient(); email
$this->inlineTranslation->suspend();
try {
$transport = $this->transportBuilder
->setTemplateIdentifier($this->helper->getConfirmationTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($replyTo)
->setFrom([
'email' => $this->contactsConfig->emailRecipient(),
'name' => $this->contactsConfig->emailSender()
])
->addTo($replyToEmail)
->setReplyTo(
$this->contactsConfig->emailRecipient(),
$this->contactsConfig->emailSender()
)
->getTransport();
$transport->sendMessage();
} finally {
$this->inlineTranslation->resume();
}
return $result;
}
Email template markup is here
https://github.com/DominicWatts/ContactResponse/blob/master/view/frontend/email/response.html
<!--@subject {{trans "Thanks for getting in touch"}} @-->
<!--@vars {
"var data.comment":"Comment",
"var data.email":"Sender Email",
"var data.name":"Sender Name",
"var data.telephone":"Sender Telephone",
} @-->
{{template config_path="design/email/header_template"}}
<table class="message-details">
<tr>
<td>Thanks for reaching out to us {{var data.name}}</strong></td>
</tr>
<tr>
<td>One of the team will be in touch soon.</td>
</tr>
</table>
{{template config_path="design/email/footer_template"}}