Send email from inside Commerce via basic mail.modPHPMailer service

Hi,
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_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,'me@example.org');
$modx->mail->set(modMail::MAIL_FROM_NAME,'Johnny Tester');
$modx->mail->set(modMail::MAIL_SUBJECT,'Check out my new email template!');
$modx->mail->address('to','user@example.com');
$modx->mail->address('reply-to','me@xexample.org');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
    $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
$modx->mail->reset();

Please advise.

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

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,'my@email.com'); // 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?