Skip to content

Instantly share code, notes, and snippets.

@Yiannistaos
Last active October 17, 2016 06:09
Show Gist options
  • Save Yiannistaos/dbfe9aee98908c2dd31638a1a99962b1 to your computer and use it in GitHub Desktop.
Save Yiannistaos/dbfe9aee98908c2dd31638a1a99962b1 to your computer and use it in GitHub Desktop.
// Send Email
function sendEmail($email_recipient = '', $subject = 'The mail subject goes here...', $body = 'The mail body goes here..')
{
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array($config->get('fromname'), $config->get('mailfrom'));
$email_recipient = (!empty($email_recipient)) ? $email_recipient : $config->get('mailfrom');
$mailer->setSender($sender);
$mailer->setSubject($subject);
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$mailer->addRecipient($email_recipient);
$send = $mailer->Send();
if ($send !== true):
mail($email_recipient, "Error sending email:", "Error sending email: ".$send->__toString());
endif;
}
// How to use the function
sendEmail("your@email.com", "Email subject goes here...", "Body text goes here...");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment