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
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);