简体   繁体   中英

Changing mail_smtp_user in a MODX snippet

My problem is quite a simple but I am not sure what is the best solution. I wish to send an email from a MODX snippet with different account/pass that is stored in MODX settings. In other words, mail_smtp_user and mail_smtp_pass should be overrided during the execution of the snippet.

I will then use $modx->mail to send an email normally.

I found a better solution.

I made new pass/user settings to the secondary email account and added the following code to the snippets that are using this secondary account.

$username = $modx->getOption("mail_smtp_secondary_user");
$password = $modx->getOption("mail_smtp_secondary_pass");
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_SMTP_PASS, $password);
$modx->mail->set(modMail::MAIL_SMTP_USER, $username);

Works well now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM