better config setup

This commit is contained in:
Brandon Shipley 2025-11-11 02:22:01 -08:00
parent 0d46eb4cc5
commit 31650e55c2
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
5 changed files with 54 additions and 25 deletions

View File

@ -8,16 +8,15 @@ return [
'email' => true,
'captcha' => true,
],
'sendConfirmationEmail' => true,
'sendBackendEmail' => true,
'clientIpHeader' => '',
'email' => [
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
'confirmation' => [
'enabled' => true,
],
'backend' => [
'confirmation' => true, // true or false
'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
'enabled' => true,
'to' => 'bshipley@hipowered.dev',
'cc' => '', // email string or array of emails
'bcc' => '', // email string or array of emails
],
],
'addIdToRedirect' => true,

View File

@ -47,14 +47,28 @@ class ContactUsFormSubmissionsMailer extends Mailer
$subject = __d('cake_contact_us', 'Contact Us Form Submitted');
$name = isset($contactUsFormSubmission['name']) ? ' by ' . $contactUsFormSubmission['name'] : '';
$to = Configure::readOrFail('ContactUs.email.backend.to');
$cc = Configure::read('ContactUs.email.backend.cc', []);
$bcc = Configure::read('ContactUs.email.backend.bcc', []);
$to = !is_array($to) ? [$to] : $to;
$this
->setTo(Configure::readOrFail('ContactUs.fields.email.backend.to'))
->setTo($to)
->setSubject($subject . $name)
->setEmailFormat(Message::MESSAGE_BOTH)
->setViewVars([
'contactUsFormSubmission' => $contactUsFormSubmission,
]);
if ($cc) {
$cc = !is_array($cc) ? [$cc] : $cc;
$this->setCc($to);
}
if ($bcc) {
$bcc = !is_array($bcc) ? [$bcc] : $bcc;
$this->setBcc($bcc);
}
$this->viewBuilder()
->setTemplate('CakeContactUs.backend');
}

View File

@ -128,7 +128,7 @@ class ContactUsFormSubmissionsTable extends Table
}
$now = DateTime::now()->format(CakeContactUsPlugin::CAKE_CONTACT_US_MYSQL_DATETIME);
$updateData = [];
if (Configure::read('ContactUs.fields.email.confirmation') && isset($contactUsFormSubmission->email)) {
if (Configure::read('ContactUs.email.confirmation', false) && isset($contactUsFormSubmission->email)) {
$mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
try {
$this->getMailer($mailer)->send('confirmation', [$contactUsFormSubmission]);
@ -137,7 +137,7 @@ class ContactUsFormSubmissionsTable extends Table
}
}
if (Configure::readOrFail('ContactUs.fields.email.backend')) {
if (Configure::read('ContactUs.email.backend.enabled', false)) {
$mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
try {
$this->getMailer($mailer)->send('backend', [$contactUsFormSubmission]);

View File

@ -142,11 +142,14 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
Configure::write('ContactUs', [
'fields' => [
'captcha' => false,
'email' => [
'confirmation' => true,
'backend' => [
'to' => 'test@example.com',
],
'email' => true,
],
'email' => [
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
'confirmation' => true, // true or false
'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
'enabled' => true,
'to' => 'test@example.com',
],
],
]);
@ -193,9 +196,14 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
Configure::write('ContactUs', [
'fields' => [
'captcha' => false,
'email' => [
'confirmation' => true,
'backend' => false,
'email' => true,
],
'email' => [
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
'confirmation' => true, // true or false
'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
'enabled' => false,
'to' => 'test@example.com',
],
],
]);
@ -236,11 +244,14 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
Configure::write('ContactUs', [
'fields' => [
'captcha' => false,
'email' => [
'confirmation' => false,
'backend' => [
'to' => 'test@example.com',
],
'email' => true,
],
'email' => [
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
'confirmation' => false, // true or false
'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
'enabled' => true,
'to' => 'test@example.com',
],
],
]);

View File

@ -63,9 +63,14 @@ Configure::write('debug', true);
Configure::write('ContactUs', [
'fields' => [
'captcha' => false,
'email' => [
'confirmation' => false,
'backend' => false,
'email' => true,
],
'email' => [
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
'confirmation' => false, // true or false
'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
'enabled' => false,
'to' => 'test@example.com',
],
],
]);