邮件内容在Joomla 3中显示为html代码

时间:2013-12-31 04:43:46

标签: php email joomla joomla3.2

我已经编写了一个用于发送邮件的脚本,它被传递到正确的电子邮件地址,但是以HTML代码形式,我不知道为什么它不起作用,因为相同的代码在Joomla 2.5中正常工作。

这是我的代码:

$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$subject = 'Account Created';
$from   = $config->get('mailfrom');
$fromname = $config->get( 'fromname' ); 

$body = "<p>Hello Test F,</p><br/><p>Thank you for registering at Deals&offers. Your account is created and activated.</p><br/>You may login to ".JURI::root().'index.php'." using the following username and password:</br><p>Username: ".$fname."</p><p>Password: ".$pwd."/p><br/><p><b>Note:</b> It is recomended to change your password after first login.</p>";

$sender = array( 
    $from,
    $fromname
);

$mailer->setSender($sender); 

$mailer->addRecipient($buyerEmail);

$mailer->setSubject($subject);

$mailer->setBody($body);

$send = $mailer->Send();

if ( $send !== true ) {
    echo 'Error sending email: ' . $send->message;
} else {
    echo 'Mail sent';
}

我也尝试过如下,但结果相同。

JFactory::getMailer()->sendMail($from,$fromname,$buyerEmail, $subject, $body);

我在邮件中收到的输出是:

<p>Hello Test F,</p><br/><p>Thank you for registering at Deals&offers. Your account is created and activated.</p><br/>You may login to http://server.ashoresystems.com/~dealsand/index.php using the following username and password:</br><p>Username: rowdy</p><p>Password: lX1XZghF/p><br/><p><b>Note:</b> It is recomended to change your password after first login.</p>

我不确定我做错了什么。如果有人有任何解决方案,请帮助。

1 个答案:

答案 0 :(得分:5)

试试这个..

对于你的第一种方法......你必须设置

$mailer->isHTML(true);

参考:http://docs.joomla.org/Sending_email_from_extensions

对于你的第二种方法......

Sendmail功能:

sendMail($from, $fromname, $recipient, $subject, $body, $htmlmode=0, $cc=null, $bcc=null, $attachment=null, $replyto=null, $replytoname=null )

所以你的代码应该是

JFactory::getMailer()->sendMail($from,$fromname,$buyerEmail, $subject, $body,true);