Home > php_mysql > Joomla send email with PHP

Joomla send email with PHP

< ?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );

define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

 $message =& JFactory::getMailer();
  $message->addRecipient("example@gmail.com");
  $message->setSubject('Your subject string');
  $message->setBody("Your body string\nin double quotes if you want to parse the \nnewlines etc");
  $sender = array( 'sender@email.address.org', 'Sender Name' );
  $message->setSender($sender);
  $message->addAttachment('htaccess.txt');
  $sent = $message->send();
  if ($sent != 1) echo 'Error sending email';
  else
  echo "OK";

?>
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.

17043 pages viewed, 1 today
11075 visits, 1 today
FireStats icon Powered by FireStats