Mail content shows as html code in Joomla 3

血红的双手。 提交于 2020-01-04 03:40:09

问题


I have written a script for sending a mail, it gets delivered to the correct email address but in them form of HTML code, I don't know why it's not working as same code is working fine in Joomla 2.5.

Here's my code:

$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';
}

I have also tried like below, but got same result.

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

the output I got in the mail is:

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

I am not sure what I am doing wrong. If anyone has any solution please help.


回答1:


Try this..

For your first method...You have to set

$mailer->isHTML(true);

Reference : http://docs.joomla.org/Sending_email_from_extensions

For your second method...

Sendmail function :

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

so your code should be

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


来源:https://stackoverflow.com/questions/20851830/mail-content-shows-as-html-code-in-joomla-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!