I have to send an e-mail using the data that's within the mysql table. I'm 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 achieve that. Please someone assist me to.

Thanks ahead of time.

vinay

You should use the JUtility class to transmit the mail:

JUtility::sendMail($mailfrom, $fromname, $recipient, $subject, $message, true);

$recipient may be the current email address you are delivering the mail to, and also the last parameter is really a flag showing if the email uses HTML or otherwise ( true = uses HTML ). However, if you need to send lots of mails, it might be easier to make use of the Joomla mailer rather than calling JUtility every time.

$mail =& JFactory::getMailer();

$mail->setSender(array($from, $fromname));
$mail->setSubject($subject);
$mail->setBody($body);
$mail->IsHTML(true);
$mail->addRecipient($recipient);
$mail->Send();

I really hope it assisted!

I am editing, I didn't remember to say working together with your data

To craft your body from the message, it might rely on the way your information is came back. Whether it's an associative array, you want to do something similar to this:

$message = "Hello {$dataarray[ 'name' ]}, thank you for adding a comment to our article {$datarray[ 'article_title']}!";

In case your "getData()" technique is coming back an item.. well actually crafting the content is simply creating a string and filling it together with your data. For large emails, It's my job to possess a template such as this:

Hello %%USERNAME%%, thank you for adding a comment to our article %%ARTICLE_TITLE%%!

After which list of positive actions 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!

This is one way php mail function works.

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Now you need the values (i.e. message) from mysql tables. You should use normal mysql instructions to fetch individuals data and after that make use of the php mail function.