Mail content shows as html code in Joomla 3

2019-07-04 09:39发布

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条回答
别忘想泡老子
2楼-- · 2019-07-04 10:17

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);
查看更多
登录 后发表回答