better config setup
This commit is contained in:
parent
0d46eb4cc5
commit
31650e55c2
|
|
@ -8,16 +8,15 @@ return [
|
||||||
'email' => true,
|
'email' => true,
|
||||||
'captcha' => true,
|
'captcha' => true,
|
||||||
],
|
],
|
||||||
'sendConfirmationEmail' => true,
|
'clientIpHeader' => '',
|
||||||
'sendBackendEmail' => true,
|
|
||||||
'email' => [
|
'email' => [
|
||||||
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
|
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
|
||||||
'confirmation' => [
|
'confirmation' => true, // true or false
|
||||||
'enabled' => true,
|
'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
|
||||||
],
|
|
||||||
'backend' => [
|
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'to' => 'bshipley@hipowered.dev',
|
'to' => 'bshipley@hipowered.dev',
|
||||||
|
'cc' => '', // email string or array of emails
|
||||||
|
'bcc' => '', // email string or array of emails
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'addIdToRedirect' => true,
|
'addIdToRedirect' => true,
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,28 @@ class ContactUsFormSubmissionsMailer extends Mailer
|
||||||
$subject = __d('cake_contact_us', 'Contact Us Form Submitted');
|
$subject = __d('cake_contact_us', 'Contact Us Form Submitted');
|
||||||
$name = isset($contactUsFormSubmission['name']) ? ' by ' . $contactUsFormSubmission['name'] : '';
|
$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
|
$this
|
||||||
->setTo(Configure::readOrFail('ContactUs.fields.email.backend.to'))
|
->setTo($to)
|
||||||
->setSubject($subject . $name)
|
->setSubject($subject . $name)
|
||||||
->setEmailFormat(Message::MESSAGE_BOTH)
|
->setEmailFormat(Message::MESSAGE_BOTH)
|
||||||
->setViewVars([
|
->setViewVars([
|
||||||
'contactUsFormSubmission' => $contactUsFormSubmission,
|
'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()
|
$this->viewBuilder()
|
||||||
->setTemplate('CakeContactUs.backend');
|
->setTemplate('CakeContactUs.backend');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class ContactUsFormSubmissionsTable extends Table
|
||||||
}
|
}
|
||||||
$now = DateTime::now()->format(CakeContactUsPlugin::CAKE_CONTACT_US_MYSQL_DATETIME);
|
$now = DateTime::now()->format(CakeContactUsPlugin::CAKE_CONTACT_US_MYSQL_DATETIME);
|
||||||
$updateData = [];
|
$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');
|
$mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
|
||||||
try {
|
try {
|
||||||
$this->getMailer($mailer)->send('confirmation', [$contactUsFormSubmission]);
|
$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');
|
$mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
|
||||||
try {
|
try {
|
||||||
$this->getMailer($mailer)->send('backend', [$contactUsFormSubmission]);
|
$this->getMailer($mailer)->send('backend', [$contactUsFormSubmission]);
|
||||||
|
|
|
||||||
|
|
@ -142,11 +142,14 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||||
Configure::write('ContactUs', [
|
Configure::write('ContactUs', [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'captcha' => false,
|
'captcha' => false,
|
||||||
'email' => [
|
'email' => true,
|
||||||
'confirmation' => true,
|
|
||||||
'backend' => [
|
|
||||||
'to' => 'test@example.com',
|
|
||||||
],
|
],
|
||||||
|
'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', [
|
Configure::write('ContactUs', [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'captcha' => false,
|
'captcha' => false,
|
||||||
|
'email' => true,
|
||||||
|
],
|
||||||
'email' => [
|
'email' => [
|
||||||
'confirmation' => true,
|
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
|
||||||
'backend' => false,
|
'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', [
|
Configure::write('ContactUs', [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'captcha' => false,
|
'captcha' => false,
|
||||||
'email' => [
|
'email' => true,
|
||||||
'confirmation' => false,
|
|
||||||
'backend' => [
|
|
||||||
'to' => 'test@example.com',
|
|
||||||
],
|
],
|
||||||
|
'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',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,14 @@ Configure::write('debug', true);
|
||||||
Configure::write('ContactUs', [
|
Configure::write('ContactUs', [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'captcha' => false,
|
'captcha' => false,
|
||||||
|
'email' => true,
|
||||||
|
],
|
||||||
'email' => [
|
'email' => [
|
||||||
'confirmation' => false,
|
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
|
||||||
'backend' => false,
|
'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',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue