# Contact form is not working

**URL:** <https://forum.getkirby.com/t/contact-form-is-not-working/30676>\
**Category:** Questions\
**Created:** [February 4, 2024, 6:45am UTC](https://forum.getkirby.com/t/contact-form-is-not-working/30676 "2024-02-04T06:45:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ete.cool](https://avatars.discourse-cdn.com/v4/letter/e/65b543/32.png) [@ete.cool](https://forum.getkirby.com/u/ete.cool)\
**Post date:** [February 4, 2024, 6:45am UTC](https://forum.getkirby.com/t/contact-form-is-not-working/30676/1 "2024-02-04T06:45:47Z")

</div>

hi…! I made contact form with kirby guide… but i can not get any mail from this…  
do you know why…?

```auto
<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

```auto
<?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…

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 4, 2024, 10:44am UTC](https://forum.getkirby.com/t/contact-form-is-not-working/30676/2 "2024-02-04T10:44:18Z")

</div>

Does the form itself work, i.e. you get to the point where the email is supposed to be sent?

How are you sending email, have you set up any [transport options](https://getkirby.com/docs/guide/emails#transport-configuration)?

Please also test if email is sent successfully: [Sending emails | Kirby CMS](https://getkirby.com/docs/guide/emails#check-if-email-is-sent-successfully), so it’s then a problem with receiving the email.

For testing forms, I’d recommend a tool like MailHog or [MailPit](https://mailpit.axllent.org/)
