用php发送包含表中数据的邮件(Mysql)

用php发送包含表中数据的邮件(Mysql),php,mysql,email,joomla,Php,Mysql,Email,Joomla,我需要发送一封包含mysql表中数据的电子邮件。我正在使用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>";

我需要发送一封包含mysql表中数据的电子邮件。我正在使用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);
$dataarray=$this->getData();//从表中返回数据
$header=“”;
$body=“此处我需要添加表数据”;
$footer=“”;
$mailer->setSubject(“邮寄”);
$mailer->setBody($header.$body.$footer);
我不知道怎么做。请有人帮帮我

提前谢谢


vinay

这是php邮件功能的工作方式

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

现在需要从mysql表中获取值(即消息)。
您可以使用普通的mysql命令获取这些数据,然后使用php邮件函数。

您可以使用JUtility类发送邮件:

JUtility::sendMail($mailfrom, $fromname, $recipient, $subject, $message, true);
$recipient是您将邮件发送到的电子邮件地址,最后一个参数是指示电子邮件是否使用HTML的标志(true=使用HTML)。 但是,如果您必须发送大量邮件,那么最好使用Joomla mailer,而不是每次都给JUtility打电话

$mail =& JFactory::getMailer();

$mail->setSender(array($from, $fromname));
$mail->setSubject($subject);
$mail->setBody($body);
$mail->IsHTML(true);
$mail->addRecipient($recipient);
$mail->Send();
我希望有帮助

我正在编辑,我忘了提到如何处理您的数据

要设计消息的主体,这将取决于数据的返回方式。 如果是关联数组,则应执行以下操作:

$message = "Hello {$dataarray[ 'name' ]}, thank you for adding a comment to our article {$datarray[ 'article_title']}!";
Hello %%USERNAME%%, thank you for adding a comment to our article %%ARTICLE_TITLE%%!
如果您的“getData()”方法正在返回对象。。事实上,构建消息只是构建一个字符串并用数据填充它。 对于非常大的电子邮件,我通常有这样一个模板:

$message = "Hello {$dataarray[ 'name' ]}, thank you for adding a comment to our article {$datarray[ 'article_title']}!";
Hello %%USERNAME%%, thank you for adding a comment to our article %%ARTICLE_TITLE%%!
然后你应该做的是:

$message=file_get_contents('your_template.tpl'); $search=array(“%%用户名%%”,“%%文章标题%%”); $replace=array($dataarray['name'],$dataarray['article_title']); $message=str_replace($search,$replace,$message)


就这些

好的,我把它弄清楚了。谢谢你的回复。我的问题不是邮件函数,而是向变量添加表内容。我只是用了。=而不是=。$mailbody=$this->getWishlists($user->id);$body.=”;foreach($mailbody作为$m){$body.=“$m->author$m->title$m->agegroup”};$body.=”;再次谢谢你,维尼。。。很高兴知道问题已经解决了。。。我以为这是关于邮件功能的,是的。=在末尾附加内容。。。