Send email from inside Commerce via basic mail.modPHPMailer service

I’m using custom registered Commerce module(class extends BaseModule) for various needs.

I need to register user and send registration email. I’m working here:

 public function updateAddress($event)

Yes, I can register new MODX user via pure MODX API (Adapter is useful here), but for some reason I can’t send email and stuck here((

I can get service next way:

$this->adapter->getService('mail', 'mail.modPHPMailer');

but further (assigning fields, sending) … nothing works. Let me remind in “pure” MODX it is done like this.

$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_FROM_NAME,'Johnny Tester');
$modx->mail->set(modMail::MAIL_SUBJECT,'Check out my new email template!');
if (!$modx->mail->send()) {
    $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);

Please advise.

$mail = $this->adapter->getService('mail', 'mail.modPHPMailer');

Alternatively if an email is order related, create it as an order message instead of sending it directly.

1 Like

Thanks a lot!

it should look like this, but after any SET call script is interrupted, there are no errors in the log. F.E.

$mail = $this->adapter->getService('mail', 'mail.modPHPMailer'); // THIS IS OK
$mail->set(modMail::MAIL_FROM,''); // INTERRUPTION`

unfortunately, this problem is still relevant, why is there a gag here? I can’t understand((, maybe someone has a fresh look from a different angle. Many thanks!

I dont know, that looks fine to me. Did you check the php/apache log?