Mail-Form-Data plugin with 2 forms only 1 working

Sorry about not providing the controllers earlier, i did not understand @texnixe … i understand so what do you suggest to fix this?

i created a second email template called email2.php.

Hello,

Phone: <?= $phone ?>,
Pickup: <?= $pick ?>,
Dropoff: <?= $drop ?>,

and in home.php controller edited to reference email2.php.

This did not solve the problem, what do you suggest.

        // the data is fine, let's send the email
        } else {
            try {
                $kirby->email([
                    'template' => 'email2',
                    'from'     => 'form@mango-media.eu',
                    'replyTo'  => $data['email'],
                    'to'       => 'hello@mango-media.eu',
                    'subject'  => 'sent you a message from your contact form',
                    'data'     => [
                        'phone' => esc($data['phone']),
                        'pick' => esc($data['pick']),
                        'drop'   => esc($data['drop']),
                    ]
                ]);

Do a dump($_POST) right after

        if($kirby->request()->is('POST') && get('submit')) {

And dump($data) before try $kirby->email() to check if you get to these places in the controller.

I have tried this but still, no email received or any error messages. I also do not see the confirmation email was sent message either:

<?php
    return function($kirby, $pages, $page) {

        $alert = null;

        if($kirby->request()->is('POST') && get('submit')) {

            dump($_POST);

            // check the honeypot
            if(empty(get('website')) === false) {
                go($page->url());
                exit;
            }

            $data = [
                'phone' => get('phone'),
                'pick'  => get('pick'),
                'drop'  => get('drop'),
            ];

            $rules = [
                'phone'  => ['required', 'minLength' => 1],
                'pick'  => ['required', 'minLength' => 1],
                'drop'  => ['required', 'minLength' => 1],
            ];

            $messages = [
                'phone' => 'Please enter valid information',
                'pick'  => 'Please enter valid information',
                'drop'  => 'Please enter valid information',
            ];

            dump($data);

            // some of the data is invalid
            if($invalid = invalid($data, $rules, $messages)) {
                $alert = $invalid;

            // the data is fine, let's send the email
            } else {
                try {
                    $kirby->email2([
                        'template' => 'email2',
                        'from'     => 'form@mango-media.eu',
                        'replyTo'  => $data['email2'],
                        'to'       => 'hello@mango-media.eu',
                        'subject'  => 'sent you a message from your contact form',
                        'data'     => [
                            'phone' => esc($data['phone']),
                            'pick' => esc($data['pick']),
                            'drop'   => esc($data['drop']),
                        ]
                    ]);

                } catch (Exception $error) {
                    if(option('debug')):
                        $alert['error'] = 'The form could not be sent ' . $error->getMessage();
                    else:
                        $alert['error'] = 'The form could not be sent!';
                    endif;
                }

                // no exception occurred, let's send a success message
                if (empty($alert) === true) {
                    $success = 'Your message has successfully been sent, thank you!<br>We will get back to you within 48 hours Monday - Friday.';
                    $data = [];
                }
            }
        }

        return [
            'alert'   => $alert,
            'data'    => $data ?? false,
            'success' => $success ?? false
        ];
    };

is it because there is no email to reply to:

                    'replyTo'  => $data['email'],

Yes, that key is undefined, so please remove. The dumps were just to test if the code is executed, not to send the email, so did you get any results from those?

okay i removed this too. I do not get any results from this either. it reloads the page on click, is this expected?

Remove this part and try again

this had no difference.

could it be related to the information in this file: mail-form-data.php

<?php

function mailFormData($data) {
    // $data (array) contains the form's sent data
    $name = $data['name'];
    $phone = $data['phone'];
    $email = $data['email'];
    $service = $data['service'];
    $pick = $data['pick'];
    $drop = $data['drop'];
    $property = $data['property'];
    $rooms = $data['rooms'];
    $package = $data['package'];
    $park = $data['park'];
    $items = $data['items'];
    
    // perform form data validation - we can use Kirby's validators,
    // available via "v":
    $errors = array();
    
    if(empty(trim($name))){ $errors[] = 'name'; }
    if(!v::email($data['email'])) { $errors[] = 'email'; }
    if(!empty($website)){ $errors[] = 'website'; }
    
    $result = array();
    $result['errors'] = $errors;
    
    // if we have validation errors, we can stop and return them:
    if(!empty($errors)){
        $result['success'] = false;
        $result['msg'] = 'Validation Failed';
        return $result;
    }
    
    // if we have no errors, we can go ahead and build an email message.
    // $to, $from and $subject can be hard-coded here, or can alternatively
    // be retrieved from values entered by the user in a page:
    $to = 'hello@mango-media.eu';
    $from = $email;
    $subject = 'Message From Your Website';
    $body = <<<BODY

From: {$name}
--------------------------------------------------------
Email: {$email}
--------------------------------------------------------
Phone: {$phone}
--------------------------------------------------------
Service: {$service}
--------------------------------------------------------
Pickup: {$pick}
--------------------------------------------------------
Dropoff: {$drop}
--------------------------------------------------------
Property: {$property}
--------------------------------------------------------
Rooms: {$rooms}
--------------------------------------------------------
Packaging: {$package}
--------------------------------------------------------
Parking: {$park}
--------------------------------------------------------
Items: {$items}
--------------------------------------------------------

BODY;
    
    // now, let's try sending the email:
    $email = email(array('to' => $to,'from' => $from,'subject' => $subject,'body' => $body));
    if($email->send()){
        // email was sent successfully
        $result['success'] = true;
        $result['msg'] = "Email sent successfully.";
    } else {
        // email delivery was not successful - report error
        $result['success'] = false;
        $result['msg'] = 'Email Delivery Failed: ' . $email->error()->message();
    }
    
    return $result;
}

i did some further testing by putting the form from the homepage on quote.php and this form did not work with or without the other form on quote.php. I also tried the form from quote.php on the home.php and this form did not work either.

@texnixe Do you have any further support please?

I have added var_dump($_POST); at the top of the controller and this appeared in the HTML: array(0) {. Does this mean the data is being submitted correctly?

No, $_POST, when not filled with data from a form, is always an empty array. $_POST should contain the form data when placed after this if statement after the form is submitted:

if($kirby->request()->is('POST')

Thank you for clarifying. Is there any way I can check the error log for further diagnosis?