Search code examples
emailjoomla

how do i send an email through joomla


I have a system so folks can register for a class through my Joomla site (I believe it's 3.0). But from there, I would like to send folks an email filling variables from the registration. So something like:

Dear (name), thank you for registering for (class). 
This is to remind you your class is tomorrow, (date), at (place).

I believe for the registration, the system uses authorize.net

How can I accomplish this?

Thanks for the help!!


Solution

  • You can use JFactory:getMailer like suggested in the following post. I'm copying here his code example (modified it a bit):

    $subject = "Here is the subject of your message.";
    $body = "Here is the body of your message.";
    $user = JFactory::getUser();
    $to = $user->email;
    $from = array("me@mydomain.com", "Brian Edgerton");
    
    # Invoke JMail Class
    $mailer = JFactory::getMailer();
    
    # Set sender array so that my name will show up neatly in your inbox
    $mailer->setSender($from);
    
    # Add a recipient -- this can be a single address (string) or an array of addresses
    $mailer->addRecipient($to);
    
    $mailer->setSubject($subject);
    $mailer->setBody($body);
    
    # If you would like to send as HTML, include this line; otherwise, leave it out
    $mailer->isHTML();
    
    # Send once you have set all of your options
    $mailer->send();
    

    That's all there is to it for sending a simple email. If you would like to add carbon copy recipients, include the following before sending the email:

    # Add a blind carbon copy
    $mailer->addBCC("blindcopy@yourdomain.com");
    

    Another alternative is using JMail::sendMail: http://docs.joomla.org/API17:JMail::sendMail