Changing mail_smtp_user in a MODX snippet

106 Views Asked by At

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.

1

There are 1 best solutions below

0
Niko Suominen On

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.