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