4

I'm currently working on a big Joomla website created by a professional company, my job is to take some of the forms and update them. I've been using the Joomla Doc most of the time, but I'm still learning to use the framework.

In the custom subscription form, I need to send two E-Mails, one for the account activation link (Which is sent during the user creation process) and the other for an overview of the user transaction (Which is also sent to the administrator). However, the system only sends one or the other, not both.

The guy who wrote the code before me cut those two mail in two function that would need a complete code overhaul to fuse, so I can't do anything about it since I'm an intern. Still, here's the important part of both methods.

First, the one during the user creation process

// Compile the notification mail values.
    $data = $user->getProperties();
    $data['fromname'] = $config->get('fromname');
    $data['mailfrom'] = $config->get('mailfrom');
    $data['sitename'] = $config->get('sitename');
    $data['siteurl'] = JUri::root();
    // Set the link to confirm the user email.
    $uri = JURI::getInstance();
    $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
    $data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'],
                    false);
    $emailSubject = JText::sprintf(
                    'COM_USERS_EMAIL_ACCOUNT_DETAILS',
                    $data['name'],
                    $data['sitename']
    );
    $emailBody = JText::sprintf(
                    'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
                    $data['name'],
                    $data['sitename'],
                    $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'],
                    $data['siteurl'],
                    $data['username'],
                    $data['password_clear']
    );
    // Send the registration email.
    JFactory::getMailer()->sendMail($data['mailfrom'],
            $data['fromname'],
            $data['email'],
            $emailSubject,
            $emailBody);

And here's the one for the transaction :

    $config = JFactory::getConfig();
    $sender = array( 
    $config->getValue('config.mailfrom'),
    $config->getValue('config.fromname'));
    $to = $values['facture_email'];
    $subject = 'xxxxxxxxxxxxxxxxxxxxxxxx ' . $values['nouveau'];
    $mailer = JFactory::getMailer();
    $mailer->setSender($sender);
    $mailer->addRecipient($to);
    $mailer->addBCC(array($from, '[email protected]'));
    $mailer->setSubject($subject);
    $mailer->isHTML(true);
    $mailer->Encoding = 'base64';
    $mailer->setBody($message);
    if (isset($values['carte']) && $values['carte'] != '')
    {
        $mailer->addAttachment(JPATH_COMPONENT . DS . 'assets' . DS . 'php' . DS . 'files' . DS . $values['carte']);
    }
    $send = $mailer->Send();

I checked the code 10 times and there is nothing in there that would prevent the second email to be sent if the first was... I suppose it's probably because I call getMailer() twice in the same event, but there is nothing in the joomla doc that would confirm this.

Thanks

7
  • In your Joomla setup what do you have in your global mail settings?
    – Craig
    Commented Jul 28, 2014 at 23:58
  • Did you try to send out the transaction mail with the same way which is used on the user creation process?
    – Laoneo
    Commented Jul 29, 2014 at 11:37
  • @cppl I've setup my email settings for my bluehost account, with SMTP and SSL security.
    – GPierre
    Commented Jul 29, 2014 at 13:39
  • @Laoneo I tried both methods, still the same problem, only the user creation mail is sent.
    – GPierre
    Commented Jul 29, 2014 at 13:54
  • Do it the hard way and an var_dump($send);die; after you sent out the second mail.
    – Laoneo
    Commented Jul 29, 2014 at 14:06

1 Answer 1

1

What joomla version you are using?

In older version of joomla the later part of the code (second chunk) might not work.

And again for the code,

$mailer->addAttachment(JPATH_COMPONENT . DS . 'assets' . DS . 'php' . DS . 'files' . DS . $values['carte']);

Try to use

$mailer->addAttachment(JPATH_COMPONENT . '/assets/php/files/'.$values['carte']);

and make sure the path eg: joomla/components/com_extend/assets/php/files/file_name exists (check in a if condition before attaching it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.