configurationmodx-revolution

MODX, transfer configuration data (ClientConfig package) to a file php


I have a script that sends an email. Can the data specified in this script be taken from the configuration fields?

Below is the php code where you need to specify the mail settings:

$mail->Host = 'eushared10.twinservers.net';
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('PV Koval System');
$mail->addAddress('prudkyi87@gmail.com');
$mail->isHTML(true);

Configuration screenshot enter image description here


Solution

  • You can work with CC settings like with other system settings using getOption() f.e.

    $mail->Host = $modx->getOption('host_setting');
    $mail->SMTPAuth = true;
    $mail->Username = $modx->getOption('login_setting');
    $mail->Password = $modx->getOption('password_setting');
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;
    $mail->setFrom($modx->getOption('from_setting'));
    $mail->addAddress($modx->getOption('email_setting'));
    $mail->isHTML(true);
    

    This is if your code is inside snippet/plugin, otherwise for external script you should add next code ot the beginning of your file :

    define('MODX_API_MODE', true);
    require dirname(__FILE__) . '/index.php';
    $modx->getService('error','error.modError');
    $modx->setLogLevel(modX::LOG_LEVEL_INFO);
    $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
    /*...*/
    $mail->Host = $modx->getOption('host_setting');
    /*...*/