本文介绍了邮件内容在Joomla 3中显示为html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经写了一个发送邮件的脚本,它被传递到正确的电子邮件地址,但以HTML代码形式,我不知道为什么它不工作,因为代码在Joomla 2.5中正常工作。这是我的代码:
$ mailer = JFactory :: getMailer ();
$ config = JFactory :: getConfig();
$ subject ='创建帐户';
$ from = $ config-> get('mailfrom');
$ fromname = $ config-> get('fromname');
$ body =< p> Hello Test F,< / p>< br />< p>感谢您在Deals& 。< / p>< br />您可以使用以下用户名和密码登录到.JURI :: root()。'index.php'。。< / br>< p>用户名: $ fname。< / p>< p>密码:$ pwd。/ p>< br />< p>< b>注意:< / b>在首次登录后更改密码。< / p>;
$ sender = array(
$ from,
$ fromname
);
$ mailer-> setSender($ sender);
$ mailer-> addRecipient($ buyerEmail);
$ mailer-> setSubject($ subject);
$ mailer-> setBody($ body);
$ send = $ mailer-> Send();
if($ send!== true){
echo'发送电子邮件时出错:'。 $发送 - >消息;
} else {
echo'Mail sent';
}
我也尝试过如下,但结果相同。
JFactory :: getMailer() - > sendMail($ from,$ fromname,$ buyerEmail,$ subject,$ body);
我收到的邮件是:
< p> Hello Test F,< / p>< br />< p>感谢您在Deals&您的帐户已创建并已激活。< / p>< br />您可以使用以下用户名和密码登录http://server.ashoresystems.com/~dealsand/index.php:< / br> < p>用户名:rowdy< / p>< p>密码:lX1XZghF / p>< br />< p>< b>注意:< / b>首先登录后,建议您更改密码。< / p>
我不知道我做错了什么
解决方案
尝试这个..
对于您的第一个方法...您必须设置
$ mailer-> isHTML(true);
参考:
对于您的第二种方法...
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);
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.
解决方案
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);
这篇关于邮件内容在Joomla 3中显示为html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!