X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FAdmin%2FForm%2FSetting%2FSmtp.php;h=cebf70c8ca4d739a60e2168019cdbaf6d5d0a77d;hb=e4d3eb19e21d0100d32703e0e7881ed9b46925fc;hp=bf1566239d13eff59196c53d7387b2fddfedf454;hpb=d9e8af2b9acdd8b6b72290a137bd95a8d3b06e73;p=civicrm-core.git diff --git a/CRM/Admin/Form/Setting/Smtp.php b/CRM/Admin/Form/Setting/Smtp.php index bf1566239d..cebf70c8ca 100644 --- a/CRM/Admin/Form/Setting/Smtp.php +++ b/CRM/Admin/Form/Setting/Smtp.php @@ -36,23 +36,25 @@ */ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { protected $_testButtonName; + protected $_settings = [ + 'allow_mail_from_logged_in_contact' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME, + ]; /** * Build the form object. */ public function buildQuickForm() { - $outBoundOption = array( + $outBoundOption = [ CRM_Mailing_Config::OUTBOUND_OPTION_MAIL => ts('mail()'), CRM_Mailing_Config::OUTBOUND_OPTION_SMTP => ts('SMTP'), CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL => ts('Sendmail'), CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED => ts('Disable Outbound Email'), CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB => ts('Redirect to Database'), - ); + ]; $this->addRadio('outBound_option', ts('Select Mailer'), $outBoundOption); CRM_Utils_System::setTitle(ts('Settings - Outbound Mail')); - $this->add('checkbox', 'allow_mail_from_logged_in_contact', ts('Allow Mail to be sent from logged in contact\'s email address')); $this->add('text', 'sendmail_path', ts('Sendmail Path')); $this->add('text', 'sendmail_args', ts('Sendmail Argument')); $this->add('text', 'smtpServer', ts('SMTP Server')); @@ -63,15 +65,17 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { $this->_testButtonName = $this->getButtonName('refresh', 'test'); - $this->addFormRule(array('CRM_Admin_Form_Setting_Smtp', 'formRule')); + $this->addFormRule(['CRM_Admin_Form_Setting_Smtp', 'formRule']); parent::buildQuickForm(); $buttons = $this->getElement('buttons')->getElements(); - $buttons[] = $this->createElement('submit', $this->_testButtonName, ts('Save & Send Test Email'), array('crm-icon' => 'fa-envelope-o')); + $buttons[] = $this->createElement('submit', $this->_testButtonName, ts('Save & Send Test Email'), ['crm-icon' => 'fa-envelope-o']); $this->getElement('buttons')->setElements($buttons); } /** * Process the form submission. + * + * @throws \Exception */ public function postProcess() { // flush caches so we reload details for future requests @@ -95,16 +99,15 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { else { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); - list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID); + list($toDisplayName, $toEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID); //get the default domain email address.CRM-4250 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') { $fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1'); - CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in Administer CiviCRM » Communications » FROM Email Addresses. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl))); + CRM_Core_Error::statusBounce(ts('The site administrator needs to enter a valid email address in Administer CiviCRM » Communications » Organization Address and Contact Info. The email address used may need to be a valid mail account with your email service provider.', [1 => $fixUrl])); } - if (!$toEmail) { CRM_Core_Error::statusBounce(ts('Cannot send a test email because your user record does not have a valid email address.')); } @@ -116,10 +119,10 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { $to = '"' . $toDisplayName . '"' . "<$toEmail>"; $from = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>'; $testMailStatusMsg = ts('Sending test email') . ':
' - . ts('From: %1', array(1 => $domainEmailAddress)) . '
' - . ts('To: %1', array(1 => $toEmail)) . '
'; + . ts('From: %1', [1 => $domainEmailAddress]) . '
' + . ts('To: %1', [1 => $toEmail]) . '
'; - $params = array(); + $params = []; if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) { $subject = "Test for SMTP settings"; $message = "SMTP settings are correct."; @@ -158,11 +161,11 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { $mailerName = 'mail'; } - $headers = array( + $headers = [ 'From' => $from, 'To' => $to, 'Subject' => $subject, - ); + ]; $mailer = Mail::factory($mailerName, $params); @@ -173,14 +176,14 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { $testMailStatusMsg .= '
' . ts('You have defined CIVICRM_MAIL_LOG_AND_SEND - mail will be logged.') . '

'; } if (defined('CIVICRM_MAIL_LOG') && !defined('CIVICRM_MAIL_LOG_AND_SEND')) { - CRM_Core_Session::setStatus($testMailStatusMsg . ts('You have defined CIVICRM_MAIL_LOG - no mail will be sent. Your %1 settings have not been tested.', array(1 => strtoupper($mailerName))), ts("Mail not sent"), "warning"); + CRM_Core_Session::setStatus($testMailStatusMsg . ts('You have defined CIVICRM_MAIL_LOG - no mail will be sent. Your %1 settings have not been tested.', [1 => strtoupper($mailerName)]), ts("Mail not sent"), "warning"); } elseif (!is_a($result, 'PEAR_Error')) { - CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', array(1 => strtoupper($mailerName))), ts("Mail Sent"), "success"); + CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', [1 => strtoupper($mailerName)]), ts("Mail Sent"), "success"); } else { $message = CRM_Utils_Mail::errorMessage($mailer, $result); - CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', array(1 => strtoupper($mailerName))) . $message, ts("Mail Not Sent"), "error"); + CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', [1 => strtoupper($mailerName)]) . $message, ts("Mail Not Sent"), "error"); } } } @@ -205,7 +208,7 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { * @param array $fields * Posted values of the form. * - * @return array + * @return array|bool * list of errors to be posted back to the form */ public static function formRule($fields) { @@ -242,7 +245,7 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { */ public function setDefaultValues() { if (!$this->_defaults) { - $this->_defaults = array(); + $this->_defaults = []; $mailingBackend = Civi::settings()->get('mailing_backend'); if (!empty($mailingBackend)) {