hi…! I made contact form with kirby guide… but i can not get any mail from this…
do you know why…?
<div class="contact-form">
<form method="post" action="<?= $page->url() ?>">
<div class="contact-form-child">
<div class="honeypot">
<label for="company"><?= t('company_name') ?></label>
<input
type="text"
id="contactCompany"
name="company"
tabindex="-1"
value=""
placeholder="Corporate name">
</div>
<div class="field">
<label for="name"><?= t('your_name') ?></label>
<input
type="text"
value="<?= esc($data['name'] ?? '', 'attr') ?>"
placeholder="Your name"
id="contactName"
name="name"
required="required">
</div>
</div>
<div class="contact-form-child">
<div class="honeypot">
<label for="title"><?= t('project_title') ?></label>
<input
type="text"
value=""
placeholder="Project title"
id="contactTitle"
name="title"
tabindex="-1">
</div>
<div class="field">
<label for="due"><?= t('project_schedule') ?></label>
<input
type="text"
value=""
placeholder="yyyy.mm.dd - yyyy.mm.dd"
id="contactDue"
name="due"
required="required">
</div>
</div>
<div class="contact-form-child">
<div class="field">
<label for="email"><?= t('email') ?></label>
<input
type="email"
value=""
placeholder="E-mail"
id="contactEmail"
name="email"
required="required">
</div>
<div class="field">
<label for="number"><?= t('phone_number') ?></label>
<input
type="text"
value=""
placeholder="Phone Number"
id="contactNum"
name="number"
required="required">
</div>
</div>
<div class="contact-form-full">
<div class="field">
<label for="category"><?= t('category') ?></label>
<div class="category-input">
<input
type="text"
value=""
placeholder="Select project category"
onfocus="showDropdown()"
id="contactCategory"
name="category"
required="required">
<svg
id="dropdownIcon"
width="23"
height="11"
viewbox="0 0 23 11"
fill="none"
xmlns="http://www.w3.org/2000/svg"
onclick="showDropdown()">
<path d="M1 1L11.5072 9L22.0144 1" stroke="#7D7D7D" stroke-width="2"/>
</svg>
<ul id="categoryDropdown" style="display: none;">
<?php
$categories = $page->formcategory()->split(',');
?>
<?php foreach ($categories as $category): ?>
<li
value="<?php echo $category; ?>"
onclick="selectCategory('<?php echo $category; ?>')"><?php echo $category; ?></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<script></script>
</div>
<div class="contact-form-full" style="padding:1rem 0">
<div class="field">
<label for="budget"><?= t('budget') ?></label>
<div class="category-input">
<input
type="text"
value=""
placeholder="Budget"
onfocus="showDropdown2()"
id="contactBudget"
name="budget"
required="required">
<svg
id="dropdownIcon2"
width="23"
height="11"
viewbox="0 0 23 11"
fill="none"
xmlns="http://www.w3.org/2000/svg"
onclick="showDropdown2()">
<path d="M1 1L11.5072 9L22.0144 1" stroke="#7D7D7D" stroke-width="2"/>
</svg>
<ul id="budgetDropdown" style="display: none;">
<?php
$budgetTags = $page->budget()->split(',');
foreach ($budgetTags as $budgetTag):
?>
<li
value="<?php echo $budgetTag; ?>"
onclick="selectBudget('<?php echo $budgetTag; ?>')"><?php echo $budgetTag; ?></li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
<div class="contact-form-full" style="padding-top:0.5rem">
<div class="field">
<label for="text"><?= t('project_detail') ?></label>
<textarea
name="text"
required="required"
id="contactText"
cols="30"
rows="10"
placeholder="Please write the project request details.">
<?php
if (isset($data['text']) && !empty($data['text'])) {
echo esc($data['text']);
}
?>
</textarea>
<script>
function clearInputValue(textarea) {
if (textarea.value === "Please write the project request details.") {
textarea.value = "";
}
}
</script>
</div>
</div>
<div class="form-bottom">
<div id="inputSumit">
<input type="submit" name="submit" value="<?= t('send') ?>" class="input-sumit">
<h7 class="btnarrow">→<h7></div>
<?php if($success): ?>
<div class="alert success">
<p><?= $success ?></p>
</div>
<?php else: ?>
<?php if (isset($alert['error'])): ?>
<div class="alert-error"><?= $alert['error'] ?></div>
<?php endif ?>
</div>
</form>
<?php endif ?>
</div>
</div>
this is my contact.php… and
<?php
return function($kirby, $pages, $page) {
$data = null;
$success = null;
if($kirby->request()->is('POST') && get('submit')) {
// Check if any field is empty
if (
empty(get('company')) ||
empty(get('name')) ||
empty(get('title')) ||
empty(get('due')) ||
empty(get('email')) ||
empty(get('number')) ||
empty(get('category')) ||
empty(get('budget')) ||
empty(get('text'))
) {
// Do nothing or set a custom error message if needed
} else {
$data = [
'company' => get('company'),
'name' => get('name'),
'title' => get('title'),
'due' => get('due'),
'email' => get('email'),
'number' => get('number'),
'category' => get('category'),
'budget' => get('budget'),
'text' => get('text')
];
$rules = [
'name' => ['required', 'minLength' => 3],
'email' => ['required', 'email'],
'text' => ['required', 'minLength' => 3, 'maxLength' => 3000],
];
$messages = [
'name' => 'Please enter a valid name',
'email' => 'Please enter a valid email address',
'text' => 'Please enter text between 3 and 3000 characters'
];
if($invalid = invalid($data, $rules, $messages)) {
// Validation failed, but no alerts are set
} else {
try {
$kirby->email([
'template' => 'email',
'from' => 'info@studio-d-d.com',
'replyTo' => $data['email'],
'to' => 'info@studio-d-d.com',
'subject' => esc($data['name']) . ' sent you a message from your contact form',
'data' => [
'text' => esc($data['text']),
'sender' => esc($data['name'])
]
]);
} catch (Exception $error) {
// Handle email sending error if needed
}
if (empty($invalid) === true) {
$success = 'Thank you!';
$data = [];
}
}
}
}
return [
'data' => $data ?? false,
'success' => $success ?? false
];
};
?>
this is controllers…
I don’t know why i can not get any mail…
please help me or give me some advise…
regards…