sendWelcomeMail(); Then it should work =========================================================================== */ define('_JEXEC', 1); //require '../../libraries/import.php'; require_once(JPATH_ROOT.'/libraries/import.php'); defined('_JEXEC') or die("JEXEC cannot not be initialized"); jimport('joomla.application.component.controller'); class customMailer { // The file that should be holds the mail text to be sent as welcome mail protected $template = '/views/orders/tmpl/welcome.tmpl'; // The file that should be attached with each welcome mail (from the tmpl directory) protected $attachment = '/views/orders/tmpl/incasso.pdf'; // The product name that should trigger the mail being sent protected $product = "HIOW basis website"; // Debug mode on or off (entries written to apache error_log) protected $debug = 1; function __construct($data) { // Use the Joomla mailer settings $this->mailer = JFactory::getMailer(); // Use the sender details configured in Joomla $config = JFactory::getConfig(); $this->email = $data['email']; $this->mailer->setSender(array("administratie@hetisonswerk.nl", "Administratie")); $this->send = False; foreach ($data['products'] as $product) { if ($this->debug) error_log("Ordered : id=" . $product['product_id'] . "name =" . $product['name']); if ($product['name'] == $this->product) { $this->send = True; } } } function setRecipient() { $this->mailer->addRecipient($this->email); if ($this->debug) error_log("Sending to {$this->email}"); } function send() { $send = $this->mailer->Send(); if ( $send !== true ) { if($this->debug) error_log("Failed to send mail"); } else { if($this->debug) error_log("Mail sent"); } } function sendWelcomeMail() { if(! $this-send) { if ($this-debug) error_log("No mail being sent as product is not {$this->product}"); return; } error_log("sendWelcomeMail called"); // Presumes the file exists - routine will die if it does not $lines = explode("\n", file_get_contents(dirname(__FILE__) . "/" . $this->template)); $this->setRecipient(); // Subject is the first line of the template if($this->debug) error_log("Set subject to {$lines[0]}" ); $this->mailer->setSubject($lines[0]); array_shift($lines); $this->mailer->isHTML(true); $this->mailer->Encoding = 'base64'; $this->mailer->setBody(implode($lines)); $this->send(); } }