I need to send an email with the data that is in the mysql table. I am using joomla1.5.
$dataarray = $this->getData(); // returns data from table
$header = "<div> <table><tr></tr>";
$body = "Here I need to add table data";
$footer = "</table></div>";
$mailer->setSubject('Mailing');
$mailer->setBody($header.$body .$footer);
I dont how to do that. Please someone help me.
Thanks in advance.
vinay
You can use the JUtility class to send the mail:
$recipient is the email address you’re sending the mail to, and the last parameter is a flag indicating whether the email uses HTML or not ( true = uses HTML ).
However, if you have to send a lot of mails, it would be better to use the Joomla mailer instead of calling JUtility each time.
I hope it helped!
I’m editing, I forgot to mention how to work with your data
To craft the body of the message, it would depend on how your data is returned.
If it’s an associative array, you should do something like this:
If your “getData()” method is returning an object.. well in fact crafting the message is just building a string and filling it with your data.
For very large emails, I usually have a template like this:
And then what you should do is:
$message = file_get_contents( ‘your_template.tpl’ );
$search = array( “%%USERNAME%%”, “%%ARTICLE_TITLE%%” );
$replace = array( $dataarray[ ‘name’ ], $dataarray[ ‘article_title’ ] );
$message = str_replace( $search, $replace, $message );
That’s all!