Hello everyone,
I know there is a lot of topic allready but I didn’t found the answer.
I followed the Email contact form cookbook step by step, just changed controllers/contact.php:
<?php
return function( $kirby, $pages, $page ) {
$alert = null;
if( $kirby->request()->is( 'POST' ) && get( 'submit' ) ) {
// check the honeypot
if( empty( get( 'website' ) ) === false ) {
go( $page->url() );
exit;
}
$data = [
'first_name' => get( 'first_name' ),
'last_name' => get( 'last_name' ),
'email' => get( 'email' ),
'text' => get( 'text' )
];
$rules = [
'first_name' => [ 'required', 'minLength' => 3 ],
'last_name' => [ 'required', 'minLength' => 3 ],
'email' => [ 'required', 'email' ],
'text' => [ 'required', 'minLength' => 3, 'maxLength' => 3000 ],
];
$messages = [
'first_name' => 'Please enter a valid first name',
'last_name' => 'Please enter a valid last name',
'email' => 'Please enter a valid email address',
'text' => 'Please enter a text between 3 and 3000 characters'
];
// 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->email( [
'template' => 'email',
'from' => 'contactform@getkirby.com',
'replyTo' => $data[ 'email' ],
'to' => esc( $page->site()->mail() ),
'subject' => esc( $data[ 'first_name' ] ) . ' ' . esc( $data[ 'last_name' ] ) . ' sent you a message from your contact form',
'data' => [
'text' => esc( $data[ 'text' ] ),
'from' => esc( $data[ 'email' ] ),
'sender' => esc( $data[ 'first_name' ] ) . ' ' . esc( $data[ 'last_name' ] )
]
] );
} catch ( Exception $error ) {
if( option( 'debug' ) ):
$alert[ 'error' ] = 'The form could not be sent: <strong>' . $error->getMessage() . '</strong>';
else:
$alert[ 'error' ] = 'The form could not be sent!';
endif;
}
// no exception occurred, let's send a success message
if ( empty( $alert ) === true ) {
$success = ucfirst( esc( $data[ 'first_name' ] ) ) . ', your message has been sent, thank you.<br>We will get back to you soon!';
$data = [];
}
}
}
return [
'alert' => $alert,
'data' => $data ?? false,
'success' => $success ?? false
];
};
I added esc( $page->site()->mail() )
to change the mail on the Kirby.
Result, the message has been sent, thank you.
but I don’t receive any message. Apart of the new data and the $page->site->mail(), everything is the same as the cookbook for now.