Home > php_mysql > Joomla send email with PHP

Joomla send email with PHP

PHP:
  1. <?php
  2. define( '_JEXEC', 1 );
  3. define('JPATH_BASE', dirname(__FILE__) );
  4.  
  5. define( 'DS', DIRECTORY_SEPARATOR );
  6.  
  7. require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
  8. require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
  9.  
  10.  $message =& JFactory::getMailer();
  11.   $message->addRecipient("example@gmail.com");
  12.   $message->setSubject('Your subject string');
  13.   $message->setBody("Your body string\nin double quotes if you want to parse the \nnewlines etc");
  14.   $sender = array( 'sender@email.address.org', 'Sender Name' );
  15.   $message->setSender($sender);
  16.   $message->addAttachment('htaccess.txt');
  17.   $sent = $message->send();
  18.   if ($sent != 1) echo 'Error sending email';
  19.   else
  20.   echo "OK";
  21.  
  22. ?>

Categories: php_mysql Tags:
  1. joomla developer
    September 17th, 2009 at 10:33 | #1

    Good stuff, helped me make an important part of my website (company’s Intranet).

    If your body contains HTML-elements which needs to be parsed:

    $message->isHTML(true);

  1. No trackbacks yet.

0 pages viewed, 0 today
0 visits, 0 today
FireStats icon Powered by FireStats